#include <stdio.h>
#include <vector>
#include <stdlib.h>

using namespace std;

const int e = 5000, q = 2000;
int n, k, p[e], a[q], b[q], vis[e], way[e], cur, start, pos[q][e], t1, t2, fin, fl;
vector<int> f[e];

void dfs(int v)
{
	if (v == fin)
		fl = 0;
	vis[v] = 1;
	for (int j = 0; j < f[v].size(); j++)
		if (!vis[f[v][j]] && fl)
		{
			way[f[v][j]] = v;
			dfs(f[v][j]);
		}
	if (!vis[p[v]] && fl)
	{
		way[p[v]] = v;
		dfs(p[v]);
	}
}

void fillpos(int v)
{
	pos[cur][v] = 1;
	if (v != start)
		fillpos(way[v]);
}

int main()
{
	freopen("twopaths.in", "r", stdin);
	freopen("twopaths.out", "w", stdout);
	scanf("%d%d", &n, &k);
	for (int i = 2; i <= n; i++)
	{
		scanf("%d", &p[i]);
		f[p[i]].push_back(i);
	}
	for (int i = 0; i < k; i++)
	{
		scanf("%d%d", &a[i], &b[i]);
		cur = i;
		start = a[i];
		fin = b[i];
		fl = 1;
		for (int j = 1; j <= n; j++)
			vis[j] = 0;
		dfs(a[i]);
		fillpos(b[i]);
	}
	int best = -1;
	for (int i = 0; i < k - 1; i++)
		for (int j = i + 1; j < k; j++)
		{
			int tmp = 0;
			for (int k = 1; k <= n; k++)
				if (pos[i][k] && pos[j][k])
					tmp++;
			if (tmp > best)
			{
				best = tmp;
				t1 = i + 1;
				t2 = j + 1;
			}
		}
	printf("%d\n%d %d", best - 1, t1, t2);
	return 0;
}