#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <algorithm>
#include <vector>


typedef long long ll;


using namespace std;


#define TASK "twopaths"


vector<vector<int> > gr;
int tin[100005];
int tout[100005];
int tim = 1;
int pr[20][100005];
int dist_to_root[100005];
int logn = 20;


void dfs(int v, int pred, int dst) {
	pr[0][v] = pred;
	tin[v] = tim++;
	dist_to_root[v] = dst;
	for (int j = 1; j < logn; j++) {
		pr[j][v] = pr[j - 1][pr[j - 1][v]];
	}
	for (int u : gr[v]) {
		if (u != pred) {
			dfs(u, v, dst + 1);
		}
	}
	tout[v] = tim++;
}


bool is_pred(int a, int b) { //a is pred b
	return tin[a] <= tin[b] && tout[b] <= tout[a];
}


int lca(int a, int b) {
	if (is_pred(a, b)) {
		return a;
	}
	else if (is_pred(b, a)) {
		return b;
	}
	else if (pr[0][a] == b) {
		return b;
	}
	else if (pr[0][b] == a) {
		return a;
	}
	for (int j = logn; j >= 0; j--) {
		if (!is_pred(pr[j][a], b)) {
			a = pr[j][a];
		}
	}
	return pr[0][a];
}


int dist(int a, int b) {
	return dist_to_root[a] + dist_to_root[b] - 2 * dist_to_root[lca(a, b)];
}


int down(int a, int b) {
	if (dist_to_root[a] > dist_to_root[b]) {
		return a;
	}
	else {
		return b;
	}
}


pair<int, int> quer[100005];


int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	freopen(TASK".in", "r", stdin);
	freopen(TASK".out", "w", stdout);
#endif // _DEBUG

	int n, k;
	cin >> n >> k;
	int p;
	gr.resize(n + 1);
	for (int i = 2; i <= n; i++) {
		cin >> p;
		gr[p].push_back(i);
		gr[i].push_back(p);
	}
	dfs(1, 1, 0);
	for (int i = 0; i < k; i++) {
		cin >> quer[i].first >> quer[i].second;
	}
	int a, b, c, d;
	int mi;
	int mj;
	int mx = -1;
	for (int i = 0; i < k; i++) {
		for (int j = i + 1; j < k; j++) {
			a = quer[i].first;
			b = quer[i].second;
			c = quer[j].first;
			d = quer[j].second;
			int inter = 0;
			if (is_pred(a, c) &&
				is_pred(a, d) &&
				is_pred(b, c) &&
				is_pred(b, d) ||
				is_pred(c, a) &&
				is_pred(c, b) &&
				is_pred(d, a) &&
				is_pred(d, b)) {
				if (a == c || a == d || b == c || b == d) {
					inter = 1;
				}
				else {
					inter = 0;
				}
			}
			else {
				int lcaab = lca(a, b);
				int v1 = down(lcaab, down(lca(a, c), lca(a, d)));
				int v2 = down(lcaab, down(lca(b, c), lca(b, d)));
				inter = dist(v1, v2);
				lcaab = lca(c, d);
				int v3 = down(lcaab, down(lca(a, c), lca(b, c)));
				int v4 = down(lcaab, down(lca(a, d), lca(b, d)));
				inter = dist(v1, v2);
				inter = min(inter, dist(v3, v4));
			}
			if (inter > mx) {
				mx = inter;
				mi = i;
				mj = j;
			}
		}
	}
	cout << mx << '\n' << mi + 1 << ' ' << mj + 1;
}