#include <iostream>
#include <set>
#include <vector>
using namespace std;

const int MAXN = 1000;
vector <int> g[MAXN];
bool used1[MAXN] = {}, color1[MAXN][MAXN] = {};
bool flag = false;
int st, fin;

void dfs(int v, int ind) {
	used1[v] = true;
	if (v == fin)
		flag = true;
	for (int i = 0; i < g[v].size(); i++) {
		if (!used1[g[v][i]] && !flag) {
			dfs(g[v][i], ind);
		}
	}
	if (flag)
		color1[ind][v] = true;

}

int main() {
	freopen("twopaths.in", "r", stdin);
	freopen("twopaths.out", "w", stdout);
	int n, k, a;
	cin >> n >> k;
	for (int i = 2; i <= n; i++) {
		scanf_s("%d", &a);
		g[i].push_back(a);
		g[a].push_back(i);
	}
	for (int i = 0; i < k; i++) {
		scanf_s("%d%d", &st, &fin);
		dfs(st, i);
		flag = false;
		for (int j = 0; j < n; j++)
			used1[j] = false;
	}
	int max_cur =  -1, ind1, ind2;
	for (int i = 0; i < k; i++) {
		for (int j = i + 1; j < k; j++) {
			int cur = 0; 
			for (int h = 1; h <= n; h++) {
				if (color1[i][h] && color1[j][h])
					cur++;
			}
			if (cur > max_cur) {
				max_cur = cur - 1;
				if (cur == 0)
					max_cur = 0;
				ind1 = i + 1;
				ind2 = j + 1;
			}
		}
	}
	cout << max_cur << endl;
	cout << ind1 << ' ' << ind2;
	return 0;
}