#include <stdio.h>
#include <vector>
#include <iostream>
#include <string>
#include <map>
#include <algorithm>

using namespace std;

#pragma warning (disable:4996)

#define mlp make_pair
#define ll long long int
#define x1 first
#define y1 second

int n, p[100007],m,t=0,r[100007];
map<int, int> edge[100007];
vector<pair<int, int> > v[100007];
pair<int, int> q[100007];

void dfs(int u, int k) {
	int i;
	if (q[k].x1 == u || q[k].y1 == u) {
		t = 1 - t;
	}
	for (i = 0; i < v[u].size(); i++) {
		r[v[u][i].y1] += t;
		if (v[u].size() != 0)dfs(v[u][i].x1, k);
		r[v[u][i].y1] -= t;
		if (r[v[u][i].y1] != 0) {
			edge[v[u][i].y1][k] = 1;
			r[v[u][i].y1] = 0;
		}
	}
}

void sol() {
	int i, j,x,y;
	cin >> n >> m;
	for (i = 1; i < n; i++) {
		cin >> j;
		j -= 1;
		v[j].push_back(mlp(i, i - 1));
	}
	for (i = 0; i < m; i++) {
		cin >> x >> y;
		x -= 1;
		y -= 1;
		q[i] = mlp(x, y);
		t = 0;
		dfs(0, i);
	}
	i = 1;
	int ans = -1;
	for (i = 0; i < m; i++) {
		for (j = i + 1; j < m; j++) {
			int now = 0;
			for (int y = 0; y < n - 1; y++) {
				if (edge[y][i] == 1 && edge[y][j] == 1)now++;
			}
			if (now > ans) {
				ans = now;
				x = i + 1;
				y = j + 1;
			}
		}
	}
	cout << ans << endl;
	cout << x << " " << y;
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	freopen("twopaths.in", "r", stdin);
	freopen("twopaths.out", "w", stdout);
#endif

	sol();

}