#include <iostream>
#include <vector>
#include <algorithm>
#define f first
#define s second
#define MAXN 200000
using namespace std;

int p[100][MAXN], n, k, tin[MAXN], tout[MAXN], timer = 1, clr[MAXN], lca[MAXN], h[MAXN];
vector<int> s[MAXN];
pair<int, int> ar[MAXN];

void dfs(int v, int he = 1)
{
	tin[v] = timer++;
	h[v] = he;
	for (auto i : s[v])
		dfs(i, he + 1);
	tout[v] = timer++;
}

int isParent(int a, int b)
{
	return tin[a] <= tin[b] && tout[b] <= tout[a];
}


int LCA(int a, int b)
{
	if (isParent(a, b))
		return a;
	if (isParent(b, a))
		return b;
	if (isParent(p[0][a], b))
		return p[0][a];
	int nxt = 0;
	for (int i = 0; i < 20; i++)
		if (!isParent(p[i][a], b))
			nxt = p[i][a];
	return LCA(nxt, b);
}



int getLca(int a, int b)
{
	if (isParent(a, b))
		return a;
	if (isParent(b, a))
		return b;
	while (!isParent(a, b))
		a = p[0][a];
	return a;
}

int inter(int a, int b, int c, int d)
{
	//cerr << a << ' ' << b << ' ' << c << ' ' << d << '\n';
	if (a == c && b == d)
		return h[b] - h[a];
	if (a == b || c == d)
		return 0;
	if (isParent(c, a) && a != c)
		return inter(c, d, a, b);
	if (isParent(b, c))
		return 0;
	if (isParent(d, b))
		return h[d] - h[c];
	if (!isParent(a, c))
		return 0;
	int o = LCA(b, d);
	return h[o] - h[c];
}

int getPath(int i, int j)
{
	return inter(lca[i], ar[i].f, lca[j], ar[j].f) + inter(lca[i], ar[i].s, lca[j], ar[j].f) + inter(lca[i], ar[i].f, lca[j], ar[j].s) + inter(lca[i], ar[i].s, lca[j], ar[j].s);
}


int main()
{
	freopen("twopaths.in", "r", stdin);
	freopen("twopaths.out", "w", stdout);
	cin >> n >> k;
	for (int i = 1; i < n; i++)
	{
		cin >> p[0][i];
		p[0][i]--;
		s[p[0][i]].push_back(i);
	}
	for (int j = 1; j < 20; j++)
	{
		for (int i = 0; i < n; i++)
		{
			p[j][i] = p[j - 1][p[j - 1][i]];
		}
	}
	for (int i = 0; i < k; i++)
	{
		cin >> ar[i].f >> ar[i].s;
		ar[i].f--;
		ar[i].s--;
		lca[i] = LCA(ar[i].f, ar[i].s);
		//		if (getLca(ar[i].f, ar[i].s) != lca[i])
		//            cerr << "ERROR\n";
	}
	dfs(0);
	int res = 0, l = 0, r = 1;
	for (int i = 0; i < k; i++)
		for (int j = i + 1; j < k; j++)
		{
			int u = getPath(i, j);
			if (u > res)
			{
				res = u;
				l = i;
				r = j;
			}
			res = max(res, getPath(i, j));
		}
	cout << res << '\n' << l + 1 << ' ' << r + 1 << '\n';
	cerr << res << '\n' << l + 1 << ' ' << r + 1 << '\n';
	return 0;
}
