#include<fstream>
#include<algorithm>
#include<vector>
#include<time.h>

using namespace std;

const int maxn = 100005;

int n, k;
vector<int> gr[maxn];
pair<int, int> kur[maxn];
int tim = 0;
int inti[maxn], outti[maxn], pos[maxn];
int pr[40][maxn];
int lg = 0;
int comm[maxn];

void dfs(int v, int p, int ps = 0) {
	inti[v] = tim++;
	pr[0][v] = p;
	pos[v] = ps;
	for (int i = 0; i < gr[v].size(); ++i)
		dfs(gr[v][i], v, ps + 1);
	outti[v] = tim++;
}

bool is_pr(int u, int v) {
	return(inti[u] <= inti[v] && outti[u] >= outti[v]);
}

int lca(int u, int v) {
	if (is_pr(u, v)) return u;
	for (int i = lg; i >= 0; --i)
		if (!is_pr(pr[i][u], v))
			u = pr[i][u];
	;
	return pr[0][u];
}

void build_lca() {
	int znstep = 2;
	for (lg = 1; znstep <= n; znstep *= 2, lg += 1) {
		for (int i = 1; i <= n; ++i)
			pr[lg][i] = pr[lg - 1][pr[lg - 1][i]];
	}
	lg -= 1;
}

int ans = 0, al = 1, ar = 2;

int getl(int i, int u, int v) {
	return (-pos[i] + pos[lca(u, v)]);
}

int get_ann(int i, int j) {
	int ann = getl(comm[j], kur[i].first, kur[j].first);
	ann = max(ann,getl(comm[j], kur[i].first, kur[j].second));
	ann = max(ann, getl(comm[j], kur[i].second, kur[j].first));
	ann = max(ann, getl(comm[j], kur[i].second, kur[j].second));
	return ann;
}

int main() {
	ios_base::sync_with_stdio(false);
	ifstream cin("twopaths.in");
	ofstream cout("twopaths.out");
	int start = clock();
	cin >> n >> k;
	for (int i = 2; i <= n; ++i) {
		int a;
		cin >> a;
		gr[a].push_back(i);
	}
	dfs(1, 1);
	build_lca();
	for (int i = 1; i <= k; ++i) {
		cin >> kur[i].first >> kur[i].second;
		comm[i] = lca(kur[i].first, kur[i].second);
	}
	for (int i = 1; i < k; ++i) {
		int end = clock();
		if (start - end >= 1900) break;
		for (int j = i + 1; j <= k; ++j) {
			if (comm[i] == comm[j]) {
				if (lca(kur[i].first, kur[j].first) != comm[i] || lca(kur[i].second, kur[j].second) != comm[i]){
					int ann = pos[lca(kur[i].first, kur[j].first)] + pos[lca(kur[i].second, kur[j].second)] - pos[comm[i]] * 2;
					if (ann > ans) {
						ans = ann;
						al = i; ar = j;
					}
				}
				else if (lca(kur[i].first, kur[j].second) != comm[i] || lca(kur[i].second, kur[j].first) != comm[i]) {
					int ann = pos[lca(kur[i].first, kur[j].second)] + pos[lca(kur[i].second, kur[j].first)] - pos[comm[i]] * 2;
					if (ann > ans) {
						ans = ann;
						al = i; ar = j;
					}
				}
			}
			else if (is_pr(comm[i], comm[j])) {
				int ann = get_ann(i, j);
				if (ann > ans) {
					ans = ann;
					al = i; ar = j;
				}
			}
			else if (is_pr(comm[j], comm[i])) {
				int ann = get_ann(j, i);
				if (ann > ans) {
					ans = ann;
					al = i; ar = j;
				}
			}
		}
	}
	cout << ans << endl;
	cout << al << " " << ar;
	return 0;
}