#include <string>
#include <map>
#include <set>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

#ifdef _DEBUG
#include <fstream>
ifstream cin("input.txt");
ofstream cout("output.txt");
#else
#include <fstream>
ifstream cin("twopaths.in");
ofstream cout("twopaths.out");
#endif

int n, k;

vector < int > g[2000];

vector < pair < int , int > > e[1000];

bool u[1000];

int pos = 0;

bool dfs(int v, int to) {

	if (v == to)
		return true;

	u[v] = true;
	for (int i = 0; i < g[v].size(); i++) {
		if (!u[g[v][i]]) {
			if (dfs(g[v][i], to)) {
				e[pos].push_back({ v , g[v][i] });
				u[v] = false;
				return true;
			}
		}
	}
	u[v] = false;
	return false;
}

bool equal(pair < int, int > a, pair < int, int > b) {
	return (a.first == b.first && a.second == b.second) || (a.first == b.second && a.second == b.first);
}

int main() {
	cin >> n >> k;
	for (int i = 0; i < n - 1; i++) {
		int last;
		cin >> last;
		last--;
		g[last].push_back(i + 1);
		g[i + 1].push_back(last);
	}
	for (int i = 0; i < k; i++) {
		int l, r;
		cin >> l >> r;
		l--;
		r--;
		dfs(l, r);
		//cout << e[pos].size() << endl;
		pos++;
	}
	int mx = 0;
	int f = 0, s = 1;
	//cout << endl;
	//for (int i = 0; i < n; i++)
	//	cout << g[i].size() << endl;
	//cout << endl;

	for (int i = 0; i < k; i++) {
		for (int j = 0; j < k; j++) {
			if (i != j) {
				int nw = 0;
				for (int l = 0; l < e[i].size(); l++) {
					for (int r = 0; r < e[j].size(); r++) {
						if (equal(e[i][l], e[j][r])) {
							nw++;
						}
					}
				}
				if (nw > mx) {
					mx = nw;
					f = i;
					s = j;
				}
			}
		}
	}
	cout << mx << endl;
	cout << f + 1 << ' ' << s + 1;
}