//#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
int n, k, a, b,i, c, j,ii, z,a1;
char ch;
vector<int> m[300000];
vector<pair<int, int> > m2[100001];
vector<pair<int, int> > v;
bool u;
void dfs(int x,int b)
{
	if (x == a1)
	{
		u = true;
		return;
	}
	for (int j = 0; j < m[x].size();j++)
		if (m[x][j] != b)
		{
			dfs(m[x][j],x);
			if (u)
			{
				m2[ii].push_back(make_pair(x, m[x][j]));
				return;
			}
		}
}
int main()
{ 
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	freopen("twopaths.in", "r", stdin);
	freopen("twopaths.out", "w", stdout);
	scanf("%d%d", &n, &k);
	for (int i = 2; i <= n; i++)
	{
		scanf("%d", &a);
		m[i].push_back(a);
		m[a].push_back(i);
	}
	for (int i = 1; i <= k; i++)
	{
		scanf("%d%d", &a, &a1);
		ii = i;
		u = false;
		dfs(a, 0);
	}
	int res = 0, ans1 = 1, ans2 = 2;
	for (int i = 1; i <= k; i++)
		for (int z = i + 1; z <= k; z++)
		{
			v.clear();
			for (int j = 0; j < m2[i].size();j++)
				v.push_back(m2[i][j]);
			for (int j = 0; j < m2[z].size(); j++)
				v.push_back(m2[z][j]);
			sort(v.begin(), v.end());
			int q = 0;
			for (int j = 1; j < v.size(); j++)
				if (v[j] == v[j - 1])
					q++;
			if (q > res)
			{
				res = q;
				ans1 = i;
				ans2 = z;
			}
			v.clear();
			for (int j = 0; j < m2[i].size(); j++)
				v.push_back(make_pair(m2[i][j].second,m2[i][j].first));
			for (int j = 0; j < m2[z].size(); j++)
				v.push_back(m2[z][j]);
			sort(v.begin(), v.end());
			q = 0;
			for (int j = 1; j < v.size(); j++)
				if (v[j] == v[j - 1])
					q++;
			if (q > res)
			{
				res = q;
				ans1 = i;
				ans2 = z;
			}
		}
	printf("%d\n", res);
	printf("%d %d", ans1, ans2);
    return 0;
}