#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <string>

using namespace std;

#define lint long long int

#define C 200005

int n, k;
int par[C];

vector<pair<int, int>> p;
vector<int> v[C];

vector<int> order;
int done[C];
int dp[C];


int first[C];
int last[C];

vector<int> tree;

#define inf 1000000000


void dfs(int cur, int depth = 0)
{
	done[cur] = 1;
	dp[cur] = depth;
	order.push_back(cur);
	for (int i = 0; i < v[cur].size(); i++)
	{
		if (done[v[cur][i]] == 0)
			dfs(v[cur][i], depth + 1);
		order.push_back(cur);
	}
}

void build(int cur, int L, int R)
{
	if (L == R)
		tree[cur] = order[L];
	else
	{
		build(2 * cur, L, (L + R) / 2);
		build(2 * cur + 1, (L + R) / 2 + 1, R);
		if (dp[tree[2 * cur]] < dp[tree[2 * cur + 1]])
			tree[cur] = tree[2 * cur];
		else
			tree[cur] = tree[2 * cur + 1];
	}
}

int Tfind(int cur, int L, int R, int l, int r)
{
	if (R < l || L > r)
		return inf;
	if (L >= l && R <= r)
		return tree[cur];
	if (L < l || R > r)
	{
		int a, b;
		a = Tfind(2 * cur, L, (L + R) / 2, l, r);
		b = Tfind(2 * cur + 1, (L + R) / 2 + 1, R, l, r);
		if (a == inf)
			return b;
		if (b == inf)
			return a;
		if (dp[a] < dp[b])
			return a;
		return b;
	}
}

bool isChild(int a, int p)
{
	return first[a] >= first[p] && last[a] <= last[p];
}

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

	cin >> n >> k;
	for (int i = 2; i <= n; i++) {
		cin >> par[i];
		done[i] = 0;
		v[par[i]].push_back(i);
		first[i] = last[i] = -1;
	}
	done[1] = 0;
	first[1] = last[1] = -1;

	for (int i = 0; i < k; i++)
	{
		int a, b;
		cin >> a >> b;
		if (b < a)
			swap(a, b);
		p.push_back(make_pair(a, b));
	}

	dfs(1);

	for (int i = 0; i < order.size(); i++)
	{
		if (first[order[i]] == -1)
			first[order[i]] = i;
		last[order[i]] = i;
	}

	tree.resize(order.size() * 4, 0);
	build(1, 0, order.size() - 1);

	int res = -1;
	int maxA, maxB;

	int curD = 1;
	for (int i = 1; i <= n; i++)
		done[i] = 0;

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

			int lca1 = Tfind(1, 1, order.size() - 1, first[p[i].first], first[p[i].second]);
			int lca2 = Tfind(1, 1, order.size() - 1, first[p[j].first], first[p[j].second]);

			int cur = p[i].first;
			while (cur != lca1)
			{
				done[cur] = curD;
				cur = par[cur];
			}
			cur = p[i].second;
			while (cur != lca1)
			{
				done[cur] = curD;
				cur = par[cur];
			}

			cur = p[j].first;
			while (cur != lca2)
			{
				curRes += (done[cur] == curD);
				cur = par[cur];
			}
			cur = p[j].second;
			while (cur != lca2)
			{
				curRes += (done[cur] == curD);
				cur = par[cur];
			}

			if (curRes > res)
			{
				res = curRes;
				maxA = i + 1;
				maxB = j + 1;
			}

			curD++;
			/*
			int cur = p[i].first;
			while (1)
			{
				if()
			}*/
		}

	cout << res << endl;
	cout << maxA << " " << maxB << endl;


	fclose(stdin);
	fclose(stdout);
	return 0;
}