#include <bits/stdc++.h>
using namespace std;

const int MAXN = 200100;

int p[MAXN];
int t;
int lcp[MAXN];

int a[MAXN], b[MAXN];



vector <int> g[MAXN];

vector <int> order;

int first[MAXN];

int tin[MAXN], tout[MAXN];
int deth[MAXN];

int up[MAXN][40];

void dfs(int v, int h)
{
	deth[v] = h;
	tin[v] = t++;
	// first[v] = order.size();
	// order.push_back(v);
	up[v][0] = p[v];
	for (int i = 1; i < 40; ++i)
		up[v][i] = up[up[v][i - 1]][i - 1];
	for (int i = 0; i < (int)g[v].size(); ++i)
	{
		dfs(g[v][i], h + 1);
		// order.push_back(v);
	}
	tout[v] = t++;
}


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

int getlcp(int u, int v)
{
	int x = 30;

	if (root(v, u))
		return v;

	if (root(u, v))
		return u;

	while (x >= 0)
	{
		if (!root(up[v][x], u))
			v = up[v][x];
		--x;
	}
	return up[v][0];
}



int main()
{	
	freopen("twopaths.in", "r", stdin);
	freopen("twopaths.out", "w", stdout);


	int n, k;
	scanf("%d%d", &n, &k);

	for (int i = 1; i < n; ++i)
	{
		scanf("%d", &p[i]);
		--p[i];
		g[p[i]].push_back(i);
	}

	dfs(0, 0);

	for (int i = 0; i < k; ++i)
	{
		scanf("%d%d", &a[i], &b[i]);
		--a[i], --b[i];

		lcp[i] = getlcp(a[i], b[i]);
		// printf("%d %d %d\n", a[i], b[i], lcp[i]);

	}

	int ans = 0;
	int inda = 1, indb = 2;

	for (int i = 0; i < k; ++i)
	{
		for (int j = i + 1; j < k; ++j)
		{
			int cur = 0;

			int v = a[i], u = a[j];

			int l = getlcp(v, u);

			if (deth[l] > deth[lcp[i]] && deth[l] > deth[lcp[j]])
				cur += deth[l] - max(deth[lcp[j]], deth[lcp[i]]);

			v = b[i], u = b[j];

			l = getlcp(v, u);
			if (deth[l] > deth[lcp[i]] && deth[l] > deth[lcp[j]])
				cur += deth[l] - max(deth[lcp[j]], deth[lcp[i]]);

			v = b[i], u = a[j];

			l = getlcp(v, u);
			if (deth[l] > deth[lcp[i]] && deth[l] > deth[lcp[j]])
				cur += deth[l] - max(deth[lcp[j]], deth[lcp[i]]);

			v = a[i], u = b[j];

			l = getlcp(v, u);
			if (deth[l] > deth[lcp[i]] && deth[l] > deth[lcp[j]])
				cur += deth[l] - max(deth[lcp[j]], deth[lcp[i]]);

			// printf("%d %d %d\n", i, j, cur);


			if (ans < cur)
            {
                ans = cur;
                inda = i + 1;
                indb = j + 1;
            }

		}
	}

	printf("%d\n%d %d\n", ans, inda, indb);




	return 0;
}