#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <string>
#include <set>
#include <vector>
using namespace std;

const int MAXN = 2222;
const int LOG = 20;

int n, k, dd;

int a[MAXN], b[MAXN];

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

bool was[MAXN][MAXN];

int ans;

int p[MAXN][LOG];

vector <int> path;

vector <vector <int> > vv;

void go1()
{
	for (int i = 1; i < path.size(); i++)
	{
		int a = min(path[i - 1], path[i]);
		int b = max(path[i - 1], path[i]);
		was[a][b] = was[b][a] = true;
	}
}

void dfs1(int v, int nd, int p = -1)
{
	path.push_back(v);
	if (v == nd)
	{
		go1();
		return;
	}
	int sz = vv[v].size();
	for (int i = 0; i < sz; i++)
	{
		if (vv[v][i] != p)
			dfs1(vv[v][i], nd, v);
	}
	path.pop_back();
}

void go2()
{
	ans = 0;
	for (int i = 1; i < path.size(); i++)
	{
		int a = min(path[i - 1], path[i]);
		int b = max(path[i - 1], path[i]);
		if (was[a][b])
			ans++;
	}
}

void dfs2(int v, int nd, int p = -1)
{
	path.push_back(v);
	if (v == nd)
	{
		go2();
		return;
	}
	int sz = vv[v].size();
	for (int i = 0; i < sz; i++)
	{
		if (vv[v][i] != p)
			dfs2(vv[v][i], nd, v);
	}
	path.pop_back();
}

int solve(int id1, int id2)
{
	memset(was, 0, sizeof was);
	int aa1 = a[id1];
	int aa2 = a[id2];
	int bb1 = b[id1];
	int bb2 = b[id2];
	path.clear();
	dfs1(aa1, bb1);
	path.clear();
	dfs2(aa2, bb2);
	return ans;
}

int main()
{
	freopen("twopaths.in", "r", stdin);
	freopen("twopaths.out", "w", stdout);
	scanf("%d %d", &n, &k);
	vv.resize(n);
	for (int i = 1; i < n; i++)
	{
		int u;
		scanf("%d", &u);
		u--;
		vv[u].push_back(i);
		vv[i].push_back(u);
	}
	for (int i = 0; i < k; i++)
	{
		scanf("%d %d", &a[i], &b[i]);
		a[i]--, b[i]--;
	}
	int ans = -1, id1 = -1, id2 = -1;
	for (int i = 0; i < k; i++)
	{
		for (int j = i + 1; j < k; j++)
		{
			int cur = solve(i, j);
			if (cur > ans)
			{
				ans = cur;
				id1 = i;
				id2 = j;
			}
		}
	}
	printf("%d\n%d %d", ans, id1 + 1, id2 + 1);
	return 0;
}