#include <fstream>
#include <vector>
#include <algorithm>

#define MAXN (int)3e5

using namespace std;

vector<vector<int>> arr;
vector<vector<int>> krs;
bool used[MAXN];
bool TAKE;


void Dfs(int v, int b, int i)
{
	used[v] = true;
	if (v == b)
	{
		TAKE = true;
		krs[i].push_back(v);
		return;
	}
	for (auto e : arr[v])
		if (!used[e])
		{
			Dfs(e, b, i);
			if (TAKE)
			{
				krs[i].push_back(v);
				return;
			}
		}
}

int Check(int a, int b)
{
	int num = krs[a].size() + krs[b].size();
	vector<int> mrg(num);
	merge(krs[a].begin(), krs[a].end(), krs[b].begin(), krs[b].end(), mrg.begin());
	num -= unique(mrg.begin(), mrg.end()) - mrg.begin();
	return max(0, num - 1);
}

int main()
{
	ifstream fin("twopaths.in");
	ofstream fout("twopaths.out");
	int n, k;
	fin >> n >> k;
	if (n > 90 && k > 90)
		return -1;
	arr.resize(n + 1);
	for (int i = 2; i <= n; i++)
	{
		int p;
		fin >> p;
		arr[p].push_back(i);
		arr[i].push_back(p);
	}
	krs.resize(k + 1);
	for (int i = 0; i < k; i++)
	{
		int a, b;
		fin >> a >> b;
		fill(used, used + n, 0);
		TAKE = false;
		Dfs(a, b, i);
		sort(krs[i].begin(), krs[i].end());
	}
	int ans = -1, A = -1, B = -1;
	for (int i = 0; i < k; i++)
		for (int j = i + 1; j < k; j++)
		{
			int ch = Check(i, j);
			if (ch > ans)
			{
				ans = ch;
				A = i;
				B = j;
			}
		}
	fout << ans << endl;
	fout << A + 1 << " " << B + 1 << endl;
	return 0;
}