#include <iostream>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <iterator>
#include <string>
#include <unordered_set>
#include <unordered_map>
#pragma warning(disable: 4996)
typedef long long ll;
typedef long double ld;
using namespace std;

const int SZ = 1e5;
const int INF = 1e9;

int par[20][SZ];
int a[SZ], b[SZ], c[SZ], depth[SZ];
vector<int> child[SZ];

void dfs(int h, int d) {
	depth[h] = d;
	for (auto i : child[h])
		dfs(i, d + 1);
}

int lca(int a, int b) {
	if (depth[a] > depth[b])
		swap(a, b);
	int dif = depth[b] - depth[a];
	int pw = 0;
	while (dif) {
		if (dif & 1)
			b = par[pw][b];
		dif >>= 1;
		pw++;
	}
	if (a == b)
		return a;
	for (int i = 19; i >= 0; i--)
		if (par[i][a] != par[i][b]) {
			a = par[i][a];
			b = par[i][b];
		}
	return par[0][a];
}

int gc(int a1, int b1, int a2, int b2) {
	if (depth[b2] < depth[a1] || depth[b1] < depth[a2])
		return 0;

	if (depth[b1] > depth[b2]) {
		int dif = depth[b1] - depth[b2];
		int pw = 0;
		while (dif) {
			if (dif & 1)
				b1 = par[pw][b1];
			dif >>= 1;
			pw++;
		}
	} else if (depth[b2] > depth[b1]) {
		int dif = depth[b2] - depth[b1];
		int pw = 0;
		while (dif) {
			if (dif & 1)
				b2 = par[pw][b2];
			dif >>= 1;
			pw++;
		}
	}

	if (depth[a1] < depth[a2]) {
		int x = b1;
		int dif = depth[b2] - depth[a2];
		int pw = 0;
		while (dif) {
			if (dif & 1)
				x = par[pw][x];
			dif >>= 1;
			pw++;
		}
		a1 = x;
	}
	else if (depth[a2] < depth[a1]) {
		int x = b2;
		int dif = depth[b1] - depth[a1];
		int pw = 0;
		while (dif) {
			if (dif & 1)
				x = par[pw][x];
			dif >>= 1;
			pw++;
		}
		a2 = x;
	}

	if (a1 != a2)
		return 0;

	for (int i = 19; i >= 0; i--)
		if (par[i][b1] != par[i][b2]) {
			b1 = par[i][b1];
			b2 = par[i][b2];
		}
	if (b1 != b2)
		b1 = par[0][b1];

	return depth[b1] - depth[a1];
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	freopen("twopaths.in", "r", stdin);
	freopen("twopaths.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	srand(654536633);

	int n, k;
	cin >> n >> k;
	for (int i = 1; i < n; i++) {
		int x;
		cin >> x;
		x--;
		par[0][i] = x;
		child[x].push_back(i);
	}
	dfs(0, 0);
	
	for (int i = 1; i < 20; i++)
		for (int j = 0; j < n; j++)
			par[i][j] = par[i - 1][par[i - 1][j]];

	for (int i = 0; i < k; i++) {
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
		c[i] = lca(a[i], b[i]);
	}

	int ans = -1, ba1, ba2;
	for (int i = 0; i < k; i++)
		for (int j = i + 1; j < k; j++) {
			int tans = gc(c[i], a[i], c[j], a[j]) +
					   gc(c[i], a[i], c[j], b[j]) +
					   gc(c[i], b[i], c[j], a[j]) +
					   gc(c[i], b[i], c[j], b[j]);
			if (tans > ans) {
				ans = tans;
				ba1 = i;
				ba2 = j;
			}
		}

	cout << ans << "\n" << ba1 + 1 << " " << ba2 + 1;

	return 0;
}