#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;
int z, x, y, 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 <int> order, depth, g[100001];
bool used[100001];
void dfs(int v, int h) {
	int 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(int v, int l, int r) {
	if (l == r) {
		d[v] = l;
	}
	else {
		int 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];
		}
	}
}
int find_min(int v, int l, int r, int x, int y) {
	if (x == l&&y == r) {
		return d[v];
	}
	else {
		int 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 {
				int s1, s2;
				s1 = find_min(v * 2, l, m, x, m);
				s2 = find_min(v * 2 + 1, m + 1, r, m + 1, y);
				if (depth[s1] < depth[s2]) {
					return s1;
				}
				else {
					return s2;
				}
			}
		}
	}
}
int lca(int a, int b) {
	if (first[a] > first[b]) {
		return order[find_min(1, 0, depth.size() - 1, first[b], first[a])];
	}
	else {
		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);
	scanf("%i", &n);
	scanf("%i", &k);
	for (i = 1; i < n; i++) {
		scanf("%i", &x);
		g[x - 1].push_back(i);
		g[i].push_back(x - 1);
	}
	for (i = 0; i < k; i++) {
		scanf("%i", &x);
		a[i] = x - 1;
		scanf("%i", &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;
			y = max(u[w[i]], u[w[j]]);
			z = u[lca(a[i], a[j])];
			if (z>y) {
				tans3 += z - y;
			}
			z = u[lca(b[i], a[j])];
			if (z>y) {
				tans3 += z - y;
			}
			z = u[lca(a[i], b[j])];
			if (z>y) {
				tans3 += z - y;
			}
			z = u[lca(b[i], b[j])];
			if (z > y) {
				tans3 += z - y;
			}
			if (tans3 > ans3) {
				ans3 = tans3;
				ans1 = i + 1;
				ans2 = j + 1;
			}
		}
	}
	cout << ans3 << endl << ans1 << " " << ans2;
}