#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <climits>

using namespace std;

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

	int n, k;
	cin >> n >> k;
	vector<int> p(n);
	vector<vector<int> > v(n);
	int tmp;
	for (int i = 1; i < n; i++) {
		scanf("%d", &tmp);
		p[i] = tmp - 1;
	}
	int a, b;
	int gposa, gposb, gmax = -1;
	for (int i = 0; i < k; i++) {
		scanf("%d%d", &a, &b);
		a--, b--;

		vector<bool> kek(n);

		int act = a;
		while (act != b && act != 0) {
			kek[act] = true;
			act = p[act];
		}
		kek[act] = true;

		act = b;
		int boss = 0;
		while (true) {
			if (kek[act] == true) {
				boss = act;
				break;
			}
			act = p[act];
		}

		vector<int> ans(k);

		act = a;
		while (act != boss) {
			for (int enemy : v[act])
				ans[enemy]++;

			v[act].push_back(i);
			act = p[act];
		}
		act = b;
		while (act != boss) {
			for (int enemy : v[act])
				ans[enemy]++;

			v[act].push_back(i);
			act = p[act];
		}

		int pos, mx = -1;
		for (int i = 0; i < k; i++)
			if (ans[i] > mx) {
				mx = ans[i];
				pos = i;
			}

		if (mx > gmax) {
			gmax = mx;
			gposa = pos;
			gposb = i;
		}
	}

	if (gmax == 0) {
		printf("0\n1 2");
		return 0;
	}

	printf("%d\n%d %d", gmax, gposa + 1, gposb + 1);

	return 0;
}