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

using namespace std;

const int sz = 1e2;
const int inf = 1e9;

struct edge {
	int to, num;
	edge() {
		to = 0;
		num = 0;
	}
	edge(int t, int n) {
		to = t;
		num = n;
	}
};

int par[sz];
vector <edge> v[sz];
int cur[sz][2];
bool was[sz];
vector <int> a[sz];

bool dfs(int cur, int need, int num) {
	was[cur] = true;
	if (cur == need) {
		return true;
	}
	for (int i = 0; i < v[cur].size(); i++){
		if (!was[v[cur][i].to]) {
			if (dfs(v[cur][i].to, need, num)) {
				a[num].push_back(v[cur][i].num);
				return true;
			}
		}
	}
	return false;
}

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	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", &par[i]);
		par[i]--;
	}
	int counter = 0;
	for (int i = 1; i < n; i++) {
		v[i].push_back(edge(par[i], counter));
		v[par[i]].push_back(edge(i, counter++));
	}
	for (int i = 0; i < k; i++) {
		for (int j = 0; j < 2; j++) {
			scanf("%d", &cur[i][j]);
			cur[i][j]--;
		}
	}
	for (int i = 0; i < k; i++) {
		for (int j = 0; j < n; j++) {
			was[j] = false;
		}
		dfs(cur[i][0], cur[i][1], i);
		sort(a[i].begin(), a[i].end());
	}
	int res = -1, one, two;
	for (int i = 0; i < k; i++) {
		for (int j = i + 1; j < k; j++) {
			int cur = 0;
			int l = 0, r = 0;
			while (l < a[i].size() && r < a[j].size()) {
					if (a[i][l] == a[j][r]) {
						cur++;
						l++;
						r++;
					}
					else if (a[i][l] < a[j][r]) {
						l++;
					}
					else {
						r++;
					}
			}
			if (cur > res) {
				res = cur;
				one = i;
				two = j;
			}
		}
	}
	printf("%d\n%d %d", res, one + 1, two + 1);
    return 0;
}

