#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <tuple>

using namespace std;

#define vec vector
#define ALL(x) (x).begin(), (x).end()
#define mp make_pair

typedef pair< int, int > pii;

const int LOG = 21;

int n, k, timer = 0;
vec< int > p, par[LOG], pid, h, tin, tout, _lca;
vec< vec< pii > > g;
vec< pii > que;

void dfs(int v, int par = -1, int H = 0) {
	h[v] = H;
	tin[v] = timer++;
	for (auto to : g[v]) {
		if (to.first != par) dfs(to.first, v, H + 1);
	}
	tout[v] = timer++;
}

void read() {
	scanf("%d %d", &n, &k);
	p.resize(n + 1, -1);
	g.resize(n + 1);
	pid.resize(n + 1, -1);

	for (int cur = 0, i = 2; i <= n; i++) {
		scanf("%d", &p[i]);
		g[i].push_back(mp(p[i], cur));
		g[p[i]].push_back(mp(i, cur));
		pid[i] = cur;
		cur++;
	}

	for (int u, v, i = 0; i < k; i++) {
		scanf("%d %d", &u, &v);
		que.push_back(mp(u, v));
	}

	for (int i = 0; i < LOG; i++) {
		par[i].resize(n + 1, -1);
	}

	par[0] = p;

	for (int i = 1; i < LOG; i++) {
		for (int j = 1; j <= n; j++) {
			int x = par[i - 1][j];
			if (x != -1) par[i][j] = par[i - 1][x];
		}
	}

	h.resize(n + 1);
	tin.resize(n + 1);
	tout.resize(n + 1);
	dfs(1);

	
}

int lca(int u, int v) {
	if (h[u] < h[v]) swap(u, v);
	for (int i = LOG - 1; i >= 0; i--) {
		int pu = par[i][u];
		if (pu == -1 || h[pu] < h[v]) continue;
		u = pu;
	}
	for (int i = LOG - 1; i >= 0; i--) {
		int pu, pv;
		pu = par[i][u];
		pv = par[i][v];
		if (pu == -1 || pv == -1 || pu == pv) continue;
		u = pu;
		v = pv;
	}
	if (u != v) u = par[0][u];
	return u;
}

int dist(int u, int v) {
	return h[u] + h[v] - 2 * h[lca(u, v)];
}

bool inTree(int root, int son) {
	return tin[root] <= tin[son] && tout[son] <= tout[root];
}

int check(int i, int j) {
	int u1, v1, u2, v2, lca1, lca2, tmp, U, V;
	u1 = que[i].first;
	v1 = que[i].second;
	lca1 = _lca[i];
	u2 = que[j].first;
	v2 = que[j].second;
	lca2 = _lca[j];
	
	tmp = 0;

	if (!inTree(lca1, lca2) && !inTree(lca2, lca2)) return 0;

	if (inTree(lca2, lca1)) {
		swap(lca1, lca2);
		swap(u1, u2);
		swap(v1, v2);
	}

	int U;

	if (inTree(lca2, u1)) {
		U = u1;  
	} else if (inTree(lca2, v1)) {
		U = v1;
	} else return 0;

	int T = lca(U, u2);

	if (inTree(lca2, T)) tmp += h[T] - h[lca2];
	else {
		T = lca(U, v2);
		if (inTree(lca2, T)) tmp += h[T] - h[lca2];
	}
	return tmp;
}

void sol() {
	int res = -1, a1, a2;

	for (int tmp, i = 0; i < k; i++) {
		for (int j = i + 1; j < k; j++) {
			tmp = check(i, j);
			if (res < tmp) {
				res = tmp;
				a1 = i + 1;
				a2 = j + 1;
			}
		}
	}
	printf("%d\n%d %d", res, a1, a2);
}

void precalc() {
	for (int i = 0; i < k; i++) {
		_lca.push_back(lca(que[i].first, que[i].second));
	}
}

int getMaxLen() {
	int res = 0;
	for (auto it : que) res = max(res, dist(it.first, it.second));
	return res;
}

void solShortPath() {
	int res = -1, a1, a2;
	vec< vec< int > > who(n - 1);
	for (int i = 0; i < k; i++) {
		int u, v;
		u = que[i].first;
		v = que[i].second;
		for (; u != _lca[i]; u = p[u]) who[pid[u]].push_back(i);
		for (; v != _lca[i]; v = p[v]) who[pid[v]].push_back(i);
	}

	for (int i = 0; i < k; i++) {
		int u, v;
		u = que[i].first;
		v = que[i].second;
		for (; u != _lca[i]; u = p[u]) {
			for()
		}
		for (; v != _lca[i]; v = p[v]) who[pid[v]].push_back(i);
	}
}

bool solve() {

	freopen("twopaths.in", "r", stdin);
	freopen("twopaths.out", "w", stdout);

	read();
	precalc();
	
	if (k <= 5000) {
		sol();
		return true;
	}

	if (getMaxLen() <= 25) {
		solShortPath();
		return true;
	}

	return true;
}

int main() {

	//while (solve());
	solve();

	return 0;
}