#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<set>
#include<cassert>
#include<vector>
using namespace std;
const int MAXN = 1007, LOGMAX = 19;
vector<int>g[MAXN];
bool used[MAXN];
int tin[MAXN], tout[MAXN];
int depth[MAXN];
int p[MAXN][LOGMAX + 1];
int timer = 1;
int pu[MAXN], pv[MAXN];
void dfs(int v, int parent, int h)
{
	used[v] = true;
	tin[v] = timer;
	depth[v] = h;
	timer++;
	p[v][0] = parent;
	for (int i = 1; i <= LOGMAX; i++)
	{
		p[v][i] = p[p[v][i - 1]][i - 1];
	}
	for (int i = 0; i < (int)g[v].size(); i++)
	{
		int to = g[v][i];
		if (!used[to])
		{
			dfs(to, v, h + 1);
		}
	}
	tout[v] = timer;
	timer++;
}
bool cmpHeight(int u, int v)
{
	return depth[u] < depth[v];
}
bool isAncestor(int u, int v) // u - ancestor of v
{
	return tin[u] <= tin[v] && tout[u] >= tout[v];
}
int getLCA(int u, int v)
{
	if (isAncestor(u, v)) return u;
	if (isAncestor(v, u)) return v;
	for (int i = LOGMAX; i >= 0; i--)
	{
		if (!isAncestor(p[u][i], v))
		{
			u = p[u][i];
		}
	}
	return p[u][0];
}
bool check(int u, int v, int x)
{
	if (isAncestor(u, x) && isAncestor(x, v)) return true;
	return isAncestor(v, x) && isAncestor(x, u);
}
bool checkPath(int u, int v, int x)
{
	int l = getLCA(u, v);
	return check(l, u, x) || check(l, v, x);
}
int calcVert(int u, int v, int a, int b)
{
	vector<int>go;
	if (check(u, v, a))
	{
		go.push_back(a);
	}
	if (check(u, v, b))
	{
		go.push_back(b);
	}
	if (check(a, b, u))
	{
		go.push_back(u);
	}
	if (check(a, b, v))
	{
		go.push_back(v);
	}
	if ((int)go.size() == 0) return 0;
	sort(go.begin(), go.end(), cmpHeight);
	return depth[go.back()] - depth[go[0]];
}
int len(int u, int v)
{
	int l = getLCA(u, v);
	return depth[u] + depth[v] - 2 * depth[l];
}
int calc(int u, int v, int a, int b)
{
	int l1 = getLCA(u, v);
	int l2 = getLCA(a, b);
	/*vector<int>go;
	if (checkPath(u, v, a))
	{
		go.push_back(a);
	}
	if (checkPath(u, v, b))
	{
		go.push_back(b);
	}
	if (checkPath(u, v, l2))
	{
		go.push_back(l2);
	}
	if (checkPath(a, b, u))
	{
		go.push_back(u);
	}
	if (checkPath(a, b, v))
	{
		go.push_back(v);
	}
	if (checkPath(a, b, l1))
	{
		go.push_back(l1);
	}
	int ans = 0;
	for (int i = 0; i < (int)go.size(); i++)
	{
		for (int j = i + 1; j < (int)go.size(); j++)
		{
			ans = max(ans, len(go[i], go[j]));
		}
	}
	return ans; */
	vector<int>pa, pb;
	while (u != l1)
	{
		pa.push_back(u);
		u = p[u][0];
	}
	while (v != l1)
	{
		pa.push_back(v);
		v = p[v][0];
	}
	pa.push_back(l1);
	while (a != l2)
	{
		pb.push_back(a);
		a = p[a][0];
	}
	while (b != l2)
	{
		pb.push_back(b);
		b = p[b][0];
	}
	pb.push_back(l2);
	int ans = 0;
	for (int i = 0; i < (int)pa.size(); i++)
	{
		for (int j = 0; j < (int)pb.size(); j++)
		{
			if (pa[i] == pb[j])
			{
				ans++;
			}
		}
	}
	if (ans > 0) ans--;
	return ans;
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	freopen("twopaths.in", "r", stdin);
	freopen("twopaths.out", "w", stdout);
	int n, m;
	scanf("%d %d", &n, &m);
	for (int i = 2; i <= n; i++)
	{
		int u;
		int v = i;
		scanf("%d", &u);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(1, 1, 1);
	for (int i = 1; i <= m; i++)
	{
		scanf("%d %d", &pu[i], &pv[i]);
	}
	int ans = 0, ansu = 1, ansv = 2;
	for (int i = 1; i <= m; i++)
	{
		for (int j = i + 1; j <= m; j++)
		{
			int tmp = calc(pu[i], pv[i], pu[j], pv[j]);
			if (tmp > ans)
			{
				ans = tmp;
				ansu = i;
				ansv = j;
			}
		}
	}
	printf("%d\n", ans);
	printf("%d %d\n", ansu, ansv);
}