#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <set>
#include <bitset>
#include <ctime>
#include <unordered_set>

using namespace std;

const int N = 1e5;
const int MAXK = 1e3;
const int K = 6e3;

int depth[N];
int p[N];
vector <int> things;
vector <int> ppl[N];
vector <int> who[N];
int arr[MAXK][MAXK];

bitset<N*MAXK/K + 10> guy[MAXK];

int main()
{
	freopen("twopaths.in", "r", stdin);
	freopen("twopaths.out", "w", stdout);
	int n, k;
	scanf("%d %d", &n, &k);
	for (int i = 1; i < n; ++i) {
		scanf("%d", &p[i]);
		--p[i];
		depth[i] = depth[p[i]] + 1;
	}
	for (int i = 0; i < k; ++i)
	{
		int a, b;
		scanf("%d %d", &a, &b);
		--a, --b;
		while (depth[a] > depth[b])
			ppl[i].push_back(a),
			who[a].push_back(i),
			a = p[a];
		while (depth[a] < depth[b])
			ppl[i].push_back(b),
			who[b].push_back(i),
			b = p[b];
		while (a != b)
			ppl[i].push_back(a),
			ppl[i].push_back(b),
			who[b].push_back(i),
			who[a].push_back(i),
			a = p[a],
			b = p[b];
	}
	for (int i = 0; i < n; ++i)
		if (who[i].size() < K)
			for (int j = 0; j < who[i].size(); ++j)
				for (int z = j + 1; z < who[i].size(); ++z)
					++arr[who[i][j]][who[i][z]];
	unordered_set <int> vals(N*MAXK / K + 10);
	vals.rehash(N*MAXK / K + 10);
	for (int i = 0; i < k; ++i)
		for (auto x : ppl[i])
			if (who[x].size() >= K)
				vals.insert(x);
	vector <int> values(vals.size());
	{
		int temp = 0;
		for (auto &x : vals)
			values[temp++] = x;
	}
	sort(values.begin(), values.end());
	int best = -1;
	pair <int, int> ans = { -1, -1 };
	for (int i = 0; i < k; ++i)
		for (auto x : ppl[i])
			if (who[x].size() >= K)
				guy[i][lower_bound(values.begin(), values.end(), x) - values.begin()] = 1;
	for (int i = 0; i < k; ++i)
		for (int j = i + 1; j < k; ++j)
		{
			int temp = (guy[i] & guy[j]).count();
			if (best < temp + arr[i][j])
				best = temp + arr[i][j],
				ans = { i, j };
		}
	cout << best << endl;
	cout << ans.first + 1 << " " << ans.second + 1 << endl;
	return 0;
}