#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream in("twopaths.in");
ofstream out("twopaths.out");
vector<vector<int>> a;
bool dfs(vector<bool> & vis, int x, int pr, int c)
{
	if (x == c) {
		vis[x] = true;
		return true;
	}
	for (int i = 0; i < a[x].size(); ++i) {
		if (a[x][i] != pr)
			if (dfs(vis, a[x][i], x, c)) {
				vis[x] = true;
				return true;
			}
	}
	return false;
}

bool dfs2(vector<bool> & vis, int x, int pr, int c, int & r)
{

	if (x == c) {
		r += vis[x];
		return true;
	}
	for (int i = 0; i < a[x].size(); ++i) {
		if (a[x][i] != pr)
			if (dfs2(vis, a[x][i], x, c, r)) {
				r += vis[x];
				return true;
			}
	}
	return false;
}

int main()
{
	int n, k;
	in >> n >> k;
	a = vector<vector<int>>(n);
	for (int i = 1; i < n; ++i) {
		int p;
		in >> p;
		a[p - 1].push_back(i);
		a[i].push_back(p - 1);
	}
	vector<pair<int, int>> b(k);
	for (int i = 0; i < k; ++i) {
		int x, y;
		in >> x >> y;
		b[i] = make_pair(x - 1, y - 1);
	}
	int rr = -1;
	pair<int, int> rrr(-1, -1);
	for (int i = 1; i < k; ++i) {
		for (int j = 0; j < i; ++j) {
			vector<bool> vis(n, false);
			int r = -1;
			dfs(vis, b[i].first, -1, b[i].second);
			dfs2(vis, b[j].first, -1, b[j].second, r);
			r = max(r, 0);
			if (rr < r) {
				rr = r;
				rrr = make_pair(i, j);
			}
		}
	}
	out << rr << '\n' << rrr.first + 1 << ' ' << rrr.second + 1;
}