//#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>

using namespace std;

ifstream cin("twopaths.in");
ofstream cout("twopaths.out");

const int MAXJ = 18;

struct vert {
	int h, jump[MAXJ];
	vector <int> e;
};

struct postman {
	int a, b;
};

const int MAXN = int(2e5);
int n, k;
vert v[MAXN];
postman pm[MAXN];

void dfs(int cur, int p, int h) {
	v[cur].h = h, v[cur].jump[0] = p;
	for (int i = 1; i < MAXJ; ++i)
		v[cur].jump[i] = v[v[cur].jump[i - 1]].jump[i - 1];
	for (int i = 0; i < v[cur].e.size(); ++i)
		dfs(v[cur].e[i], cur, h + 1);
}

int lca(int a, int b) {
	if (v[a].h < v[b].h)
		swap(a, b);
	for (int i = MAXJ - 1; v[a].h > v[b].h; --i)
		if (v[v[a].jump[i]].h >= v[b].h)
			a = v[a].jump[i];
	if (a == b)
		return a;
	for (int i = MAXJ - 1; i >= 0; --i)
		if (v[a].jump[i] != v[b].jump[i])
			a = v[a].jump[i], b = v[b].jump[i];
	return v[a].jump[0];
}

int common_path(int a1, int b1, int a2, int b2) {
	int c1 = lca(a1, b1);
	if (c1 != a1 && c1 != b1)
		return common_path(a1, c1, a2, b2) + common_path(b1, c1, a2, b2);
	int c2 = lca(a2, b2);
	if (c2 != a2 && c2 != b2)
		return common_path(a1, b1, a2, c2) + common_path(a1, b1, b2, c2);
	if (a1 == c1)
		swap(a1, b1);
	if (a2 == c2)
		swap(a2, b2);
	int a_0 = lca(a1, a2);
	if (lca(a_0, b1) != b1 || lca(a_0, b2) != b2)
		return 0;
	int b_0 = (v[b1].h > v[b2].h) ? b1 : b2;
	return v[a_0].h - v[b_0].h;
}

int main() {
	cin >> n >> k;
	for (int i = 1; i < n; ++i) {
		int p;
		cin >> p;
		--p;
		v[p].e.push_back(i);
	}
	for (int i = 0; i < k; ++i) {
		cin >> pm[i].a >> pm[i].b;
		--pm[i].a, --pm[i].b;
	}
	dfs(0, 0, 0);
	int ans = 0, ans_1 = 1, ans_2 = 2;
	for (int i = 0; i < k; ++i)
		for (int j = i + 1; j < k; ++j) {
			int cur_ans = common_path(pm[i].a, pm[i].b, pm[j].a, pm[j].b);
			if (cur_ans > ans)
				ans = cur_ans, ans_1 = i + 1, ans_2 = j + 1;
		}
	cout << ans << endl;
	cout << ans_1 << ' ' << ans_2 << endl;
	cin >> n;
	return 0;
}