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

using namespace std;

vector <int> g[100000];
set < pair<int, int> > s[2];
int used[100000], col[100000];
bool dfs(int v, int to, int q)
{
	used[v] = 1;
	bool check = 0;
	if (v != to)
		for (int i = 0; i < g[v].size(); ++i)
		{
			if (used[g[v][i]] == 0)
			{
				s[q].insert(make_pair(min(v, g[v][i]), max(v, g[v][i])));
				check = dfs(g[v][i], to, q);
				if (check)
					i = g[v].size() + 1;
				else
					s[q].erase(make_pair(min(v, g[v][i]), max(v, g[v][i])));
			}
		}
	else
		check = 1;
	return check;
}


int main()
{
	    freopen("video.in", "r", stdin);
	    freopen("video.out", "w", stdout);
	//ios::sync_with_stdio();
	int n, m, a;
	cin >> n >> m;
	for (int i = 0; i < n - 1; ++i)
	{
		cin >> a;
		--a;
		g[i + 1].push_back(a);
		g[a].push_back(i + 1);
	}
	vector <pair <int, int > > p(m);
	for (int i = 0; i < m; ++i)
	{
		cin >> p[i].first >> p[i].second;
	}
	int ans = 0, mx;
	bool ch;
	int lf = 1, rg = 2;
	for (int i = 0; i < m; ++i)
	{
		mx = 0;
		for (int j = i + 1; j < m; ++j)
		{
			for (int tr = 0; tr < n; ++tr)
				used[tr] = 0, col[tr] = 0;
			mx = 0;
			s[0].clear();
			s[1].clear();
			ch = dfs(p[i].first - 1, p[i].second - 1, 0);

			for (int tr = 0; tr < n; ++tr)
				used[tr] = 0, col[tr] = 0;
			ch = dfs(p[j].first - 1, p[j].second - 1, 1);
			for (auto st : s[0])
			{
				if (s[1].find(st) != s[1].end())
					++mx;
			}
			if (mx > ans)
				ans = mx, lf = i + 1, rg = j + 1;
		}
	}
	cout << ans << endl << lf << ' ' << rg << endl;
}
