#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>

using namespace std;

struct cur {
	int v1, v2;
};


const int LEN = 2e5 + 10;



vector<int> v[LEN];
cur a[LEN];
int in[LEN];
int out[LEN];
int p[LEN];
int tm = 0;
set<pair<int, int> > m;

void dfs(int u) {
	in[u] = tm++;
	int sz = v[u].size();
	for (int i = 0; i < sz; ++i) {
		if (v[u][i] != p[u]) {
			dfs(v[u][i]);
		}
	}
	out[u] = tm++;
}

bool isps(int u, int v) {
	return ((in[u] <= in[v]) && (out[u] >= out[v]));
}

void fpth(int u, int v) {
	while (!(isps(u, v))) {
		m.insert(make_pair(min(u, p[u]), max(u, p[u])));
		u = p[u];
	}
	while (v != u) {
		m.insert(make_pair(min(v, p[v]), max(v, p[v])));
		v = p[v];
	}
}

int cnt = 0;
void cntd(int u, int v) {
	while (!(isps(u, v))) {
		if (m.find(make_pair(min(u, p[u]), max(u, p[u]))) != m.end()) {
			++cnt;
		}
		u = p[u];
	}
	while (v != u) {
		if (m.find(make_pair(min(v, p[v]), max(v, p[v]))) != m.end()) {
			++cnt;
		}
		v = p[v];
	}
}

int main() {
	freopen("twopaths.in", "rt", stdin);
	freopen("twopaths.out", "wt", stdout);

	int n, k;
	scanf("%d%d", &n, &k);
	int x;

	for (int i = 0; i < n - 1; ++i) {
		scanf("%d", &x);
		p[i + 1] = x - 1;
		v[i + 1].push_back(x - 1);
		v[x - 1].push_back(i + 1);
	}

	for (int i = 0; i < k; ++i) {
		scanf("%d%d", &a[i].v1, &a[i].v2);
		--a[i].v1;
		--a[i].v2;
	}
	dfs(0);
	int mx = -1, mi, mj;
	for (int i = 0; i < k; ++i) {
		for (int j = i + 1; j < k; ++j) {
			cnt = 0;
			m.clear();
			fpth(a[i].v1, a[i].v2);
			cntd(a[j].v1, a[j].v2);
			if (cnt > mx) {
				mx = cnt;
				mi = i;
				mj = j;
			}

		}
	}

	printf("%d\n%d %d", mx, mi + 1, mj + 1);

	return 0;
}