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

using namespace std;

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

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 fl1(int v1, int v2, int mn, int ls) {
	if (v1 == v2)
		return mn;
	int k = -1;
	if (!ch[v1].empty()) {
		for (set<int>::iterator i = ch[v1].begin(); i != ch[v1].end(); i++) {
			if (*i != ls)
				k = max(k, fl1(*i, v2, mn, v1));
			if (k > 0)
				break;
		}
	}
	if (k == -1 && pr[v1] != ls)
		return fl1(pr[v1], v2, pr[v1], v1);
	return k;
}

int fl(int v1, int v2) {
	if (n > 4000)
		return fl1(v1, v2, v1, -1);
	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);
	cin >> n >> k;
	pr.resize(n);
	ch.resize(n);
	if (n <= 4000) {
		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);
	}
	if (n <= 4000)
		getch(0);
	vector <pair<int, int>>c(k);
	vector <int> lca(k);
	vector < set < int > > pt(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 h = c[i].first;
		while (h != lca[i]) {
			pt[i].insert(h);
			h = pr[h];
		}
		h = c[i].second;
		while (h != lca[i]) {
			pt[i].insert(h);
			h = pr[h];
		}
	}
	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++) {
			set<int> t;
			for (set<int>::iterator k = pt[i].begin(); k != pt[i].end(); k++) {
				if (pt[j].find(*k) != pt[j].end())
					t.insert(*k);
			}
			if (t.size() > mx) {
				mx = t.size();
				l = i;
				r = j;
			}
		}
	}
	cout << mx << endl;
	cout << l + 1 << ' ' << r + 1;
	return 0;
}