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

using namespace std;

int n, k, timer = 0, ansi, ansj, sum = -1, tmps;
vector<vector<int> > g;
vector<pair<int, int> > a;
vector<int> par, tin, tout, col;

void dfs(int v) {
	tin[v] = timer++;
	for (int i = 0; i < size(g[v]); i++) {
		dfs(g[v][i]);
	}
	tout[v] = timer++;
}

void dfs2(int v, int tn, int tot) {
	col[v] = 1;
	if (tin[v] <= tn && tot <= tout[v]) {
		return;
	}
	dfs2(par[v], tn, tot);
}

void dfs3(int v, int tn, int tot) {
	tmps += col[v];
	col[v] = 0;
	if (tin[v] <= tn && tot <= tout[v]) {
		return;
	}
	dfs3(par[v], tn, tot);
}

int main() {
	freopen("twopaths.in", "r", stdin);
	freopen("twopaths.out", "w", stdout);
	cin >> n >> k;
	g.resize(n);
	par.resize(n);
	tin.resize(n);
	tout.resize(n);
	col.resize(n, 0);
	a.resize(k);
	for (int i = 1; i < n; i++) {
		int tmp;
		cin >> tmp;
		tmp--;
		g[tmp].push_back(i);
		par[i] = tmp;
	}
	dfs(0);
	for (int i = 0; i < k; i++) {
		int v, u;
		cin >> v >> u;
		v--, u--;
		if (tin[v] > tin[u]) {
			swap(v, u);
		}
		a[i] = { v, u };
	}
	for (int i = 0; i < k; i++) {
		for (int j = i + 1; j < k; j++) {
			int v = a[i].first, u = a[i].second;
			tmps = 0;
			
			dfs2(v, min(tin[v], tin[u]), max(tout[v], tout[u]));
			dfs2(u, min(tin[v], tin[u]), max(tout[v], tout[u]));

			v = a[j].first, u = a[j].second;

			dfs3(v, min(tin[v], tin[u]), max(tout[v], tout[u]));
			dfs3(u, min(tin[v], tin[u]), max(tout[v], tout[u]));

			if (tmps > sum) {
				sum = tmps;
				ansi = i;
				ansj = j;
			}
		}
	}
	cout << sum - 1<< '\n';
	cout << ansi + 1 << ' ' << ansj + 1 << '\n';
    return 0;
}

