#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <bitset>

using namespace std;

int solve();

#define TASK "twopaths"

typedef long long ll;

#define forn(i, n) for (int i = 0; i < n; i++)
#define fornn(i, q, n) for (int i = q; i < n; i++)
#define all(v) v.begin(), v.end()
#define mp make_pair

int main() {
#ifdef KAZAN
	freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
#else
	freopen(TASK".in", "r", stdin), freopen(TASK".out", "w", stdout);
#endif
	solve();
	return 0;
}

vector<vector<int> > e, J, S;
vector < vector<pair<int, int> > > T;

const int dd = 2e2 + 7;

const int maxH = 19;

int up[maxH][1 << maxH];
int tin[dd], tout[dd], pr[dd];
int tmm = 1;
int h[dd];
map<pair<int, int>, int> M[dd];

int cnt[5007][5007];

void dfs(int v, int pr) {
	tin[v] = tmm++;

	h[v] = (pr == -1 ? 0 : h[pr] + 1);

	if (v == 0) {
		forn(i, maxH)
			up[i][v] = 0;
	}
	else {
		up[0][v] = pr;

		fornn(i, 1, maxH) {
			up[i][v] = up[i - 1][up[i - 1][v]];
		}
	}

	for (int to : e[v]) {
		dfs(to, v);
	}

	tout[v] = tmm++;
}

bool par(int a, int b) {
	return tin[a] <= tin[b] && tout[b] <= tout[a];
}

int lca(int a, int b) {
	if (par(a, b))
		return a;
	if (par(b, a))
		return b;

	for (int i = maxH - 1; i >= 0; i--) {
		if (!par(up[i][a], b))
			a = up[i][a];
	}
	return up[0][a];
}

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

	e.resize(n);
	T.resize(n);
	S.resize(k);
	J.resize(n);

	forn(i, n - 1) {
		int t;
		scanf("%d", &t);

		pr[i + 1] = t - 1;
		e[t - 1].push_back(i + 1);
	}

	dfs(0, -1);

	forn(i, k) {
		int a, b;
		scanf("%d %d", &a, &b);

		a--, b--;

		S[i].push_back(a);
		S[i].push_back(b);

		int t = lca(a, b);

		int x = a, y = b;

		while (x != t) {
			T[x].push_back(mp(a, i));
			x = pr[x];
		}

		while (y != t) {
			T[y].push_back(mp(b, i));
			y = pr[y];
		}

		//if (a != t)
		//T[t].push_back(mp(a, i));
		//if (b != t)
		//T[t].push_back(mp(b, i));

		J[t].push_back(i);
	}

	forn(v, n) {


		forn(cc, T[v].size()) {

			int i = T[v][cc].second;
			int to1 = T[v][cc].first;

			int croot = -1;
			for (int to : e[v]) {
				if (par(to, to1))
					croot = to;
			}

			for (int j : J[v]) {
				for (int to2 : S[j]) {

					if (!par(croot, to2))
						continue;

					if (i == j)
						continue;

					int t = lca(to1, to2);

					cnt[i][j] += (h[t] - h[v]);
					cnt[j][i] += (h[t] - h[v]);
				}
			}
		}

		forn(cc, J[v].size()) {

			int i = J[v][cc];

			for (int to1 : S[i]) {

				int croot = -1;
				for (int to : e[v]) {
					if (par(to, to1))
						croot = to;
				}

				fornn(c, cc + 1, J[v].size()) {
					int j = J[v][c];

					for (int to2 : S[j]) {

						if (!par(croot, to2))
							continue;

						if (i == j)
							continue;

						int t = lca(to1, to2);

						cnt[i][j] += (h[t] - h[v]);
						cnt[j][i] += (h[t] - h[v]);
					}
				}
			}
		}
	}

	int ia = 0, ib = 1;

	forn(i, k) {
		forn(j, k) {
			if (cnt[i][j] > cnt[ia][ib]) {
				ia = i;
				ib = j;
			}
		}
	}

	printf("%d\n", cnt[ia][ib]);
	printf("%d %d", ia + 1, ib + 1);

	return 0;
}