#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];
vector<int> g[MAXN];
int par[MAXN][20];
int tin[MAXN], tout[MAXN];
int depth[MAXN];
int dfst = 0;

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 = 19; i >= 0; i--) {
		if (!is_anc(par[ptr][i], v))
			ptr = par[ptr][i];
	}

	return par[ptr][0];
}

inline int get_isect(int u, int v, int a, int b) {
	int lca = get_lca(v, b);
	if (depth[lca] < max(depth[a], depth[u]))
		return 0;

	return depth[lca] - max(depth[a], depth[u]);
}

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);
	}

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

	int ans = 0, ansf = 0, anss = 1;
	for (int i = 0; i < K; i++) {
		scanf("%d %d", &A[i], &B[i]);
		A[i]--, B[i]--;
	}

	int lca1, lca2;
	int dans;
	int isect1, isect2;
	for (int i = 0; i < K; i++) {
		for (int j = i+1; j < K; j++) {
			lca1 = get_lca(A[i], B[i]);
			lca2 = get_lca(A[j], B[j]);

			isect1 = max(get_isect(lca1, A[i], lca2, A[j]), get_isect(lca1, A[i], lca2, B[j]));
			isect2 = max(get_isect(lca1, B[i], lca2, A[j]), get_isect(lca1, B[i], lca2, B[j]));

			dans = isect1 + isect2;

			if (ans < dans) {
				ans = dans;
				ansf = i;
				anss = j;
			}
		}
	}

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

	return 0;
}