#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>

#pragma warning(disable:4996)

using namespace std;

vector <int> pr(2 * 1e5);
vector <int> rnk(2 * 1e5);
vector <vector <int> > d(2 * 1e5, vector <int>(20));
int lca(int a, int b) {
	int a1 = a;
	int b1 = b;
	if (rnk[a1] < rnk[b1])
		swap(a1, b1);
	int pd = rnk[a1] - rnk[b1];
	for (int st = 19; st >= 0; st--)
		if (pd &(1 << st)) {
			a1 = d[a1][st];
			pd -= (1 << st);
		}
	if (a1 == b1)
		 return b1;
	else
		for (int st = 19; st >= 0; st--)
			if (d[a1][st] != d[b1][st]) {
				a1 = d[a1][st];
				b1 = d[b1][st];
			}
	return pr[a1];
}
int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	freopen("twopaths.in", "r", stdin);
	freopen("twopaths.out", "w", stdout);
#endif
	int n;
	cin >> n;
	int k;
	cin >> k;
	for (int i = 1; i < n; i++) {
		cin >> pr[i];
		pr[i]--;
		rnk[i] = rnk[pr[i]] + 1;
	}
	for (int i = 0; i < n; i++)
		d[i][0] = pr[i];
	for (int j = 1; j < 20; j++)
		for (int i = 0; i < n; i++)
			d[i][j] = d[d[i][j - 1]][j - 1];
	vector <vector <int> > c(k, vector <int>(2));
	for (int i = 0; i < k; i++)
		cin >> c[i][0] >> c[i][1];
	for (int i = 0; i < k; i++) {
		c[i][0]--;
		c[i][1]--;
	}
	for (int i = 0; i < k; i++)
		if (c[i][0] < c[i][1])
			swap(c[i][0], c[i][1]);
	vector <int> op(k);
	for (int i = 0; i < k; i++)
		op[i] = lca(c[i][0], c[i][1]);
	int ans = -1; int l = 0; int r = 1;
	for (int i = 0; i < k; i++)
		for (int j = 0; j < i; j++)
			if (op[i] == op[j]) {
				int v1 = c[i][0];
				int v2 = c[i][1];
				int u1 = c[j][0];
				int u2 = c[j][1];
				if (lca(v1, u1) == lca(v2, u2))
					swap(v1, u1);
				int dl = rnk[lca(v1, u1)] + rnk[lca(v2, u2)] - 2 * rnk[op[i]];
				if (dl > ans) {
					ans = dl;
					l = i;
					r = j;
				}
			}
			else {
				int v1 = c[i][0];
				int u1 = c[i][1];
				int v2 = c[j][0];
				int u2 = c[j][1];
				int op1 = op[i];
				int op2 = op[j];
				if (rnk[op[i]] > rnk[op[j]]) {
					swap(v1, u1);
					swap(v2, u2);
					swap(op1, op2);
				}
				if (lca(v1, v2) > rnk[op1]) {
					int dl = abs(rnk[lca(v1, u2)] - rnk[lca(v1, v2)]);
					if (dl > ans) {
						ans = dl;
						l = i;
						r = j;
					}
				}
				if (lca(u1, v2) > rnk[op1]) {
					int dl = abs(rnk[lca(u1, u2)] - rnk[lca(u1, v2)]);
					if (dl > ans) {
						ans = dl;
						l = i;
						r = j;
					}
				}
			}
			cout << max(ans,0) << endl << l + 1 << " " << r + 1 << endl;
	return 0;
}