#define	_CRT_SECURE_NO_WARNINGS
#define	_USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cassert>
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <deque>
#include <vector>

#define	mp	make_pair

using namespace std;

const int MAXN = 200000;
const int INF = 1000000010;

typedef	long long int	ll;
typedef	long double		ld;
typedef	pair<int, int>	ii;
typedef	vector<int>		vi;
typedef	vector<ii>		vii;

int N, K;
int A[MAXN], B[MAXN], LCA[MAXN];
vector<int> g[MAXN];
set<ii> s;
ii cl[MAXN], cl1[MAXN];
int par[MAXN][20];
int tin[MAXN], tout[MAXN];
int depth[MAXN];
int dfst = 0;
int ans = 0;
int ansf = 0, anss = 1;
int cura, curb, curi;
int cnt[MAXN], cnt1[MAXN];

void dfs(int u, int p = 0) {
	tin[u] = dfst++;

	par[u][0] = p;
	for (int i = 1; i < 20; i++) {
		par[u][i] = par[par[u][i - 1]][i - 1];
	}

	for (auto it = g[u].begin(); it != g[u].end(); it++) {
		depth[*it] = depth[u] + 1;
		dfs(*it, u);
	}

	tout[u] = dfst++;
}

inline bool is_anc(int u, int v) {
	return tin[u] <= tin[v] && tout[v] <= tout[u];
}

inline int get_lca(int u, int v) {
	int ptr = u;

	if (is_anc(u, v))
		return u;

	for (int i = 17; i >= 0; i--) {
		if (!is_anc(par[ptr][i], v))
			ptr = par[ptr][i];
	}

	return par[ptr][0];
}

void update_cl(int u) {
	if (u == cura)
		return;

	ii tmp;
	tmp = mp(depth[cura], curi);

	if (tmp < cl[u]) {
		cl1[u] = cl[u];
		cl[u] = tmp;
	}
	else if (tmp < cl1[u]) {
		cl1[u] = tmp;
	}

	update_cl(par[u][0]);
}

void find_ans(int u) {
	if (u == cura)
		return;

	ii tmp = cl[u];
	if (tmp.second == curi)
		tmp = cl1[u];

	if (tmp.first != INF) {
		int dans = depth[u] - max(depth[curi], tmp.first);
		if (!cnt[tmp.second])
			cnt[tmp.second] = dans;

		if (dans + cnt1[tmp.second] > ans) {
			ans = dans + cnt1[tmp.second];
			ansf = curi;
			anss = tmp.second;
		}
	}

	find_ans(par[u][0]);
}

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

	scanf("%d %d", &N, &K);
	int pi;
	for (int i = 1; i < N; i++) {
		scanf("%d", &pi);
		pi--;
		g[pi].push_back(i);
		cl[i] = mp(INF, -1);
		cl1[i] = mp(INF, -1);
	}

	depth[0] = 0;
	dfs(0);

	for (int i = 0; i < K; i++) {
		scanf("%d %d", &A[i], &B[i]);
		A[i]--, B[i]--;
		LCA[i] = get_lca(A[i], B[i]);

		curi = i;
		cura = LCA[i];

		curb = A[i];
		update_cl(curb);

		curb = B[i];
		update_cl(curb);
	}

	for (int i = 0; i < K; i++) {
		cura = LCA[i];
		curi = i;

		memset(cnt, 0, K*sizeof(cnt[0]));
		memset(cnt1, 0, K*sizeof(cnt1[0]));

		curb = A[i];
		find_ans(A[i]);

		swap(cnt, cnt1);

		curb = B[i];
		find_ans(B[i]);
	}

	printf("%d\n%d %d", ans, ansf + 1, anss + 1);

	return 0;
}