#include<iostream>
#include<fstream>
#include<string>
#include<algorithm>
#include<vector>

using namespace std;

#define all(x) x.begin(), x.end()
#define ll long long

int tin[10001], tout[10001];
int timer = 0;
bool used[100001];
vector<int> g[100001];
vector<pair<int, int>> way[100001];
int nx[100001];

void dfs(int v) {
	used[v] = 1;
	tin[v] = timer++;
	for (auto q : g[v])
		if (!used[q])
			dfs(q);
	tout[v] = timer++;
}

bool f(int a, int b) {
	return (tin[a] <= tin[b] && tout[a] >= tout[b]);
}

int main() {
	ios_base::sync_with_stdio(0);
	freopen("twopaths.in", "r", stdin);
	freopen("twopaths.out", "w", stdout);
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n - 1; i++) {
		int c;
		cin >> c;
		g[c].push_back(i + 2);
		nx[i + 2] = c;
	}
	dfs(1);
	for (int j = 0; j < k; j++) {
		int a, b;
		cin >> a >> b;
		int v;
		for (int c = min(a, b); c >= 1; c--) {
			if (f(c, a) && f(c, b)) {
				v = c;
				break;
			}
		}
		//cout << v << "\n";
		int x1 = a;
		while (x1 != v) {
			way[j].push_back(make_pair(x1, nx[x1]));
			way[j].push_back(make_pair(nx[x1], x1));
			x1 = nx[x1];
		}
		x1 = b;
		while (x1 != v) {
			way[j].push_back(make_pair(x1, nx[x1]));
			way[j].push_back(make_pair(nx[x1], x1));
			x1 = nx[x1];
		}
		sort(all(way[j]));
		//cout << j << ": ";
		//for (int i = 0; i < way[j].size(); i++)
		//  cout << way[j][i] << " ";
		//cout << "\n";
	}
	int ans = -1, x = 1, y = 2;
	for (int i = 0; i < k / 10; i++)
		for (int j = 0; j < k / 10; j++) {
			if (i == j)
				continue;
			int c = 0;
			for (int r = 0; r < way[i].size(); r++) {
				c += (binary_search(all(way[j]), way[i][r]));
			}
			c /= 2;
			if (c > ans) {
				ans = c;
				x = i + 1, y = j + 1;
			}
		}
	cout << ans << "\n" << x << " " << y;
}