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

int p[300000];
int n, k, lgn;
vector < vector < int > > g;
int timer = 0;
int tin[300001];
int tout[300001];
int upp[300001][20];
int za[200000];
int zb[200000];
int hh[300001];

void dfs(int v = 1, int h = 1)
{
	tin[v] = timer++;
	hh[v] = h;
	for (int i = 0; i < g[v].size(); ++i)
	{
		dfs(g[v][i], h + 1);
		upp[g[v][i]][0] = v;
	}
	tout[v] = timer++;
}

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

int lca(int a, int b)
{
	if (a == b) return a;
	if (upper(a, b)) return a;
	if (upper(b, a)) return b;
	for (int i = lgn; i >= 0; --i)
		if (upper(upp[a][i + 1], b) && !upper(upp[a][i], b))
			a = upp[a][i];
	return upp[a][0];
}

int main()
{
	freopen("twopaths.in", "r", stdin);
	freopen("twopaths.out", "w", stdout);
	scanf("%d%d", &n, &k);
	g.resize(n + 1);
	for (int i = 2; i <= n; ++i)
	{
		scanf("%d", &p[i]);
		g[p[i]].push_back(i);
	}
	dfs();
	while (1 << lgn < n) ++lgn;
	for (int h = 1; h <= lgn; ++h)
		for (int i = 1; i <= n; ++i)
			upp[i][h] = upp[upp[i][h - 1]][h - 1];
	int ans = 0, ans1 = 0, ans2 = 1;
	for (int i = 0; i < k; ++i)
	{
		scanf("%d%d", &za[i], &zb[i]);
		int a_d = zb[i], a_u = za[i];
		for (int j = 0; j < i; ++j)
		{
			int b_d = zb[j], b_u = za[j];
			int a_lca = lca(a_d, a_u);
			int b_lca = lca(b_d, b_u);
			int lca1 = lca(a_d, b_d);
			int lca2 = lca(a_u, b_u);
			int lca3 = lca(a_d, b_u);
			int lca4 = lca(a_u, b_d);
			int cans = 0,
			cans1 = max(cans, hh[lca1] - max(hh[a_lca], hh[b_lca])),
			cans2 = max(cans, hh[lca2] - max(hh[a_lca], hh[b_lca])),
			cans3 = max(cans, hh[lca3] - max(hh[a_lca], hh[b_lca])),
			cans4 = max(cans, hh[lca4] - max(hh[a_lca], hh[b_lca]));
			cans = max(cans, cans1 + cans2);
			cans = max(cans, cans3 + cans4);
			if (cans > ans)
			{
				ans = cans;
				ans1 = j;
				ans2 = i;
			}
		}
	}
	printf("%d\n%d %d\n", ans, ans1 + 1, ans2 + 1);
	return 0;
}