#include <fstream>
#include <vector>
#include <algorithm>

#define ff first
#define ss second
#define mp make_pair
using namespace std;

vector<vector<int>> dp;
vector<int> height;

void lca_preprocess(vector<int>& pi) {
	height.assign(pi.size(), 0);
	for (int i = 1; i < pi.size(); ++i)
		height[i] = height[pi[i]] + 1;
	dp.push_back(pi);
	int h = 1;
	for (int i = 1; h <= pi.size(); ++i) {
		h *= 2;
		vector<int> line(pi.size(), -1);
		for (int v = 0; v < line.size(); ++v) {
			line[v] = dp.back()[v];
			if (line[v] >= 0)
				line[v] = dp.back()[line[v]];
		}
		dp.push_back(line);
	}
}

int lca(pair<int, int> a) {
	int u = a.ff, v = a.ss;
	if (height[u] <= height[v])
		swap(u, v);
	int h = dp.size() - 1;
	if (height[u] > height[v]) {
		int delta = height[u] - height[v];
		while ((1 << h) > delta) --h;
		u = dp[h][u];
	}
	if (u == v) return u;
	for (int h = dp.size() - 1; h >= 0; --h) {
		if (dp[h][u] != dp[h][v]) {
			u = dp[h][u];
			v = dp[h][v];
		}
	}
	return dp[0][u];
}

int calc(vector<int>& pi,
	pair<int, int> a, pair<int, int> b) {
	int lca_a = lca(a);
	int lca_b = lca(b);
	vector<pair<int, int>> edges_a, edges_b;
	for (int v = a.ff; v != lca_a; v = pi[v]) {
		edges_a.push_back(mp(v, pi[v]));
		edges_a.push_back(mp(pi[v], v));
	}
	for (int v = a.ss; v != lca_a; v = pi[v]) {
		edges_a.push_back(mp(v, pi[v]));
		edges_a.push_back(mp(pi[v], v));
	}
	for (int v = b.ff; v != lca_b; v = pi[v]) {
		edges_b.push_back(mp(v, pi[v]));
		edges_b.push_back(mp(pi[v], v));
	}
	for (int v = b.ss; v != lca_b; v = pi[v]) {
		edges_b.push_back(mp(v, pi[v]));
		edges_b.push_back(mp(pi[v], v));
	}
	sort(edges_a.begin(), edges_a.end());
	sort(edges_b.begin(), edges_b.end());
	int l = 0, r = 0;
	int ans = 0;
	while (l < edges_a.size() && r < edges_b.size()) {
		if (edges_a[l] == edges_b[r]) {
			++ans; ++l; ++r;
		}
		else if (edges_a[l] < edges_b[r]) {
			++l;
		}
		else ++r;
	}
	return ans / 2;
}

int main() {
	ifstream fin("twopaths.in");
	ofstream fout("twopaths.out");
	int n, k; fin >> n >> k;
	//vector<vector<int>> G(n, vector<int>());
	vector<int> pi(n);
	pi[0] = -1;
	for (int i = 1; i < n; ++i) {
		int j; fin >> j; --j;
		//G[j].push_back(i);
		pi[i] = j;
	}
	lca_preprocess(pi);
	vector<pair<int, int>> pairs(k);
	for (int i = 0; i < k; ++i) {
		fin >> pairs[i].ff >> pairs[i].ss;
		--pairs[i].ff;
		--pairs[i].ss;
	}
	int max_val = -1, max_a, max_b;
	for (int i = 0; i < k; ++i) {
		for (int j = i + 1; j < k; ++j) {
			int trial = calc(pi, pairs[i], pairs[j]);
			if (trial > max_val) {
				max_val = trial;
				max_a = i + 1; max_b = j + 1;
			}
		}
	}
	fout << max_val << "\n";
	fout << max_a << " " << max_b << "\n";
	return 0;
}