#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

vector < set <int> > pch, ch;
vector < vector < int > > dist;
vector <int> pr;

void getch(int v) {
	for (set< int >::iterator i = ch[v].begin(); i != ch[v].end(); i++) {
		getch(*i);
		pch[v].insert(*i);
		dist[v][*i] = 1;
		for (set<int>::iterator j = pch[*i].begin(); j != pch[*i].end(); j++) {
			pch[v].insert(*j);
			dist[v][*j] = dist[*i][*j] + 1;
		}
	}
}

int fl(int v1, int v2) {
	if (v1 == v2)
		return v1;
	if (pch[v1].find(v2) != pch[v1].end())
		return v1;
	else
		return fl(pr[v1], v2);
}

int main() {
	freopen("twopaths.in", "r", stdin);
	freopen("twopaths.out", "w", stdout);
	int n, k;
	cin >> n >> k;
	pr.resize(n);
	ch.resize(n);
	pch.resize(n);
	dist.resize(n, vector <int>(n, 0));
	for (int i = 1; i < n; i++) {
		int x;
		cin >> x;
		pr[i] = x - 1;
		ch[x - 1].insert(i);
	}
	getch(0);
	vector <pair<int, int>>c(k);
	vector <int> lca(k);
	for (int i = 0; i < k; i++) {
		cin >> c[i].first >> c[i].second;
		c[i].first--;
		c[i].second--;
		lca[i] = fl(c[i].first, c[i].second);
	}
	int mx = 0;
	int l, r;
	l = 0;
	r = 1;
	for (int i = 0; i < k; i++) {
		for (int j = i + 1; j < k; j++) {
			int x = fl(lca[i], lca[j]);
			if (x == lca[i]) {
				if (fl(lca[j], c[i].first) == x)
					swap(c[i].first, c[i].second);
				if (fl(c[j].first, c[i].first) == lca[j])
					swap(c[j].first, c[j].second);
				int q = fl(c[i].first, c[j].first);
				if (dist[lca[j]][q] > mx) {
					mx = dist[lca[j]][q];
					l = i;
					r = j;
				}
			}
			if (x == lca[j]) {
				if (fl(lca[i], c[j].first) == x)
					swap(c[j].first, c[j].second);
				if (fl(c[i].first, c[j].first) == lca[i])
					swap(c[i].first, c[i].second);
				int q = fl(c[j].first, c[i].first);
				if (dist[lca[i]][q] > mx) {
					mx = dist[lca[i]][q];
					l = i;
					r = j;
				}
			}
		}
	}
	cout << mx << endl;
	cout << l + 1 << ' ' << r + 1;
	return 0;
}