#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <vector>
#include <string>

using namespace std;

const int N = 100000;
int pred[N];
int h[N];
int p[N], q[N];

int main()
{
	freopen("twopaths.in", "r", stdin);
	freopen("twopaths.out", "w", stdout);

	int n, k;
	cin >> n >> k;
	h[1] = 0;
	for (int i = 2; i <= n; i++) {
		cin >> pred[i];
		h[i] = h[pred[i]] + 1;
	}
	for (int i = 0; i < k; i++) {
		cin >> p[i] >> q[i];
	}
	int ans[3]; ans[0] = -1;
	for (int i = 0; i < k; i++) {
		for (int j = i + 1; j < k; j++) {
			int res = 0;
			int a = p[i], b = q[i], c = p[j], d = q[j];
			if (h[a] > h[b]) swap(a, b);
			if (h[c] > h[d]) swap(c, d);
			while (a != b && c != d) {
				if (h[b] > h[d]) {
					b = pred[b];
				}
				else if (h[d] > h[b]) {
					d = pred[d];
				}
				else {
					if (b == d) {
						res++;
						b = pred[b];
						d = pred[d];
					}
					else if (b == c) {
						res++;
						b = pred[b];
						c = pred[c];
					}
					else if (a == d) {
						res++;
						a = pred[a];
						d = pred[d];
					}
					else {
						b = pred[b];
						d = pred[d];
					}
				}
				if (h[a] > h[b]) swap(a, b);
				if (h[c] > h[d]) swap(c, d);
			}
			if (res > ans[0]) {
				ans[0] = res;
				ans[1] = i;
				ans[2] = j;
			}
		}
	}
	cout << ans[0] << endl;
	cout << ans[1] + 1 << " " << ans[2] + 1 << endl;
	//for (;;);
}

/*

4 2
1 2 2
1 3
1 4

4 2
1 2 3
1 2
3 4

7 3
1 2 2 4 5 5
1 3
3 7
6 1

*/