#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

typedef pair <int, int> pii;
const int mn = 100010;
const int lg = 20;
int n, k, timer;
int p[mn][lg], a[mn], b[mn], c[mn], tin[mn], tout[mn], dep[mn];
pii pa[mn];
vector <int> e[mn];

void dfs(int v) {
	tin[v] = timer;
	timer++;
	for (int i = 0; i < e[v].size(); i++) {
		dfs(e[v][i]);
	}
	tout[v] = timer;
	timer++;
}

bool isans(int v, int u) {
	if (tin[v] <= tin[u] && tout[u] <= tout[v]) {
		return true;
	}
	return false;
}

int lca(int v, int u) {
	if (isans(v, u)) {
		return v;
	}
	if (isans(u, v)) {
		return u;
	}
	int q = lg - 1;
	while (q > 0) {
		while (q > 0 && isans(p[v][q], u)) {
			q--;
		}
		v = p[v][q];
	}
	if (!isans(v, u)) {
		v = p[v][0];
	}
	return v;
}

int cross(int v1, int u1, int v2, int u2) {
	if (v1 == u1) {
		return 0;
	}
	if (v2 == u2) {
		return 0;
	}
	if (dep[v1] >= dep[u2] || dep[v2] >= dep[u1]) {
		return 0;
	}
	if (!isans(v1, u2) || !isans(v2, u1)) {
		return 0;
	}
	if (dep[v1] < dep[v2]) {
		v1 = v2;
	}
	u1 = lca(u1, u2);
	return dep[u1] - dep[v1];
}

int main() {
	freopen("twopaths.in", "r", stdin);
	freopen("twopaths.out", "w", stdout);
	scanf("%d%d", &n, &k);
	p[0][0] = 0;
	dep[0] = 1;
	for (int i = 1; i < n; i++) {
		scanf("%d", &p[i][0]);
		p[i][0]--;
		e[p[i][0]].push_back(i);
		dep[i] = dep[p[i][0]] + 1;
	}
	for (int j = 1; j < lg; j++) {
		for (int i = 0; i < n; i++) {
			p[i][j] = p[p[i][j - 1]][j - 1];
		}
	}
	timer = 0;
	dfs(0);
	for (int i = 0; i < k; i++) {
		scanf("%d%d", &a[i], &b[i]);
		a[i]--;
		b[i]--;
		if (b[i] < a[i]) {
			int q = a[i];
			a[i] = b[i];
			b[i] = q;
		}
		pa[i].first = a[i];
		pa[i].second = b[i];
	}
	sort(pa, pa + k);
	for (int i = 0; i < k; i++) {
		a[i] = pa[i].first;
		b[i] = pa[i].second;
	}
	for (int i = 0; i < k; i++) {
		c[i] = lca(a[i], b[i]);
	}
	int m1 = 0, m2 = 1, ans = 0;
	for (int i = 0; i < k; i++) {
		for (int j = i + 1; j < min(i + k, k); j++) {
			int q = 0;
			q += cross(c[i], a[i], c[j], a[j]);
			q += cross(c[i], b[i], c[j], a[j]);
			q += cross(c[i], a[i], c[j], b[j]);
			q += cross(c[i], b[i], c[j], b[j]);
			if (q > ans) {
				ans = q;
				m1 = i;
				m2 = j;
			}
		}
	}
	cout << ans << "\n" << m1 + 1 << " " << m2 + 1;
	return 0;
}