#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;
long x, k, n, i, j, w[100001], a[100001], b[100001], first[100001], s[100001], d[100001], u[100001], ans1 = 0, ans2 = 0, ans3 = -1, tans1, tans2, tans3;
vector <long> order, depth, g[100001];
bool used[100001];
void dfs(long v, long h) {
	long q;
	used[v] = true;
	u[v] = h;
	order.push_back(v);
	depth.push_back(h);
	first[v] = order.size() - 1;
	for (q = 0; q < g[v].size(); q++) {
		if (used[g[v][q]] == false) {
			dfs(g[v][q], h + 1);
			order.push_back(v);
			depth.push_back(h);
		}
	}
}
void add(long v, long l, long r) {
	if (l == r) {
		d[v] = l;
	}
	else {
		long m = (l + r) / 2;
		add(v * 2, l, m);
		add(v * 2 + 1, m + 1, r);
		if (depth[d[2 * v]] < depth[d[2 * v + 1]]) {
			d[v] = d[v * 2];
		}
		else {
			d[v] = d[v * 2 + 1];
		}
	}
}
long find_min(long v, long l, long r, long x, long y) {
	if (x == l&&y == r) {
		return d[v];
	}
	else {
		long m = (l + r) / 2;
		if (x > m) {
			return find_min(v * 2 + 1, m + 1, r, x, y);
		}
		else {
			if (y <= m) {
				return find_min(v * 2, l, m, x, y);
			}
			else {
				if (depth[find_min(v * 2, l, m, x, m)] < depth[find_min(v * 2 + 1, m + 1, r, m+1, y)]) {
					return find_min(v * 2, l, m, x, m);
				}
				else {
					return find_min(v * 2 + 1, m + 1, r, m+1, y);
				}
			}
		}
	}
}
long lca(long a, long b) {
	if (first[a]>first[b]) {
		swap(a, b);
	}
	return order[find_min(1, 0, depth.size() - 1, first[a], first[b])];
}
int main() {
	freopen("twopaths.in", "r", stdin);
	freopen("twopaths.out", "w", stdout);
	cin >> n >> k;
	for (i = 1; i < n; i++) {
		cin >> x;
		g[x-1].push_back(i);
		g[i].push_back(x - 1);
	}
	for (i = 0; i < k; i++) {
		cin >> x;
		a[i] = x - 1;
		cin >> x;
		b[i] = x - 1;
	}
	dfs(0, 0);
	add(1, 0, depth.size() - 1);
	for (i = 0; i < k; i++) {
		w[i] = lca(a[i], b[i]);
	}
	for (i = 0; i < k; i++) {
		for (j = 0; j < i; j++) {
			tans3 = 0;
			tans1 = i + 1;
			tans2 = j + 1;
			if (u[lca(a[i], a[j])]>max(u[w[i]], u[w[j]])) {
				tans3 += u[lca(a[i], a[j])] - max(u[w[i]], u[w[j]]);
			}
			if (u[lca(b[i], a[j])]>max(u[w[i]], u[w[j]])) {
				tans3 += u[lca(b[i], a[j])] - max(u[w[i]], u[w[j]]);
			}
			if (u[lca(a[i], b[j])]>max(u[w[i]], u[w[j]])) {
				tans3 += u[lca(a[i], b[j])] - max(u[w[i]], u[w[j]]);
			}
			if (u[lca(b[i], b[j])] > max(u[w[i]], u[w[j]])) {
				tans3 += u[lca(b[i], b[j])] - max(u[w[i]], u[w[j]]);
			}
			if (tans3>ans3) {
				ans3 = tans3;
				ans1 = tans1;
				ans2 = tans2;
			}
		}
	}
	cout << ans3 << endl << ans1 << " " << ans2;
}