#include <bits/stdc++.h>
using namespace std;

int n, k;
vector<vector<int>> children;
vector<int> par;
vector<int> a, b, l;
vector<vector<int>> up;
vector<int> h;
const int LG = 20;

vector<int> ord, ind;
vector<int> from, to;
vector<pair<int, int>> minh_path;
vector<pair<int, int>> it;

pair<int, int> relax(pair<int, int> r, int x) {
	if (x == -1) {
		return r;
	}
	if (r.first == -1 || h[l[x]] < h[l[r.first]]) {
		return {x, r.first};
	}
	if (r.first != x && (r.second == -1 || h[l[x]] < h[l[r.second]])) {
		return {r.first, x};
	}
	return r;
}

void count_up() {
	up.resize(LG);
	for (int i = 0; i < LG; i++) {
		up[i].resize(n);
	}
	
	for (int i = 0; i < n; i++) {
		up[0][i] = par[i];
	}
	for (int i = 1; i < LG; i++) {
		for (int j = 0; j < n; j++) {
			up[i][j] = up[i - 1][up[i - 1][j]];
		}
	}
}

int lca(int a, int b) {
	for (int i = LG - 1; i >= 0; i--) {
		if (h[up[i][a]] >= h[b]) {
			a = up[i][a];
		}
		if (h[up[i][b]] >= h[a]) {
			b = up[i][b];
		}
	}
	
	if (a == b) {
		return a;
	}
	
	for (int i = LG - 1; i >= 0; i--) {
		if (up[i][a] != up[i][b]) {
			a = up[i][a];
			b = up[i][b];
		}
	}
	
	return par[a];
}

void dfs(int u) {
	from[u] = ord.size();
	ind[u] = ord.size();
	ord.push_back(u);
	for (int v : children[u]) {
		dfs(v);
	}
	to[u] = ord.size();
}

void init(int u, int L, int R) {
	if (R - L == 1) {
		it[u] = minh_path[L];
		return;
	}
	int M = (R + L) / 2;
	init(2 * u + 1, L, M);
	init(2 * u + 2, M, R);
	it[u] = it[2 * u + 1];
	it[u] = relax(it[u], it[2 * u + 2].first);
	it[u] = relax(it[u], it[2 * u + 2].second);
}

pair<int, int> getMin(int u, int L, int R, int left, int right) {
	if (L >= right || left >= R) {
		return {-1, -1};
	}
	if (left <= L && R <= right) {
		return it[u];
	}
	int M = (R + L) / 2;
	auto v1 = getMin(2 * u + 1, L, M, left, right);
	auto v2 = getMin(2 * u + 2, M, R, left, right);
	v1 = relax(v1, v2.first);
	v1 = relax(v1, v2.second);
	return v1;
}

int main() {
	freopen("twopaths.in", "r", stdin);
	#ifndef DEBUG
	freopen("twopaths.out", "w", stdout);
	#endif
	
	scanf("%d%d", &n, &k);
	par.resize(n);
	children.resize(n);
	h.resize(n);
	par[0] = 0;
	for (int i = 0; i < n - 1; i++) {
		scanf("%d", &par[i + 1]);
		par[i + 1]--;
		h[i + 1] = h[par[i + 1]] + 1;
		children[par[i + 1]].push_back(i + 1);
	}
	count_up();
	
	a.resize(k);
	b.resize(k);
	l.resize(k);
	for (int i = 0; i < k; i++) {
		scanf("%d%d", &a[i], &b[i]);
		a[i]--;
		b[i]--;
		l[i] = lca(a[i], b[i]);
	}
	
	from.resize(n);
	to.resize(n);
	ind.resize(n);
	dfs(0);
	
	// only one intersection
	minh_path.resize(n);
	for (int i = 0; i < n; i++) {
		minh_path[i] = {-1, -1};
	}
	for (int i = 0; i < k; i++) {
		// b[i] <---- l[i]
		minh_path[ind[b[i]]] = relax(minh_path[ind[b[i]]], i);
		//if (minh_path[ind[b[i]]] == -1 || h[l[minh_path[ind[b[i]]]]] > h[l[i]]) {
		//	mih_path[ind[b[i]]] = i;
		//}
		// a[i] <---- l[i]
		minh_path[ind[a[i]]] = relax(minh_path[ind[a[i]]], i);
		//if (minh_path[ind[a[i]]] == -1 || h[l[minh_path[ind[a[i]]]]] > h[l[i]]) {
		//	mih_path[ind[a[i]]] = i;
		//}
	}
	
	it.resize(4 * n);
	init(0, 0, n);
	
	int best = 0;
	int ans1 = 0, ans2 = 1;
	for (int d = 0; d < n; d++) {
		auto pind = getMin(0, 0, n, from[d], to[d]);
		if (pind.first != -1 && pind.second != -1) {
			int h2 = h[l[pind.second]];
			int hd = h[d];
			int len = hd - h2;
			if (len > best) {
				best = len;
				ans1 = pind.first;
				ans2 = pind.second;
			}
		}
	}
	
	cout << best << endl;
	cout << ans1 + 1 << " " << ans2 + 1 << endl;

	return 0;
}
