#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <cassert>
#include <memory.h>
#include <iomanip>
#include <bitset>

using namespace std;

//#define int long long
#define sz(a) (int)(a.size())

const int MAXN = 5555;
vector<int> g[MAXN];
pair<pair<int, int>, int> cur[MAXN];
int n, k;
int z1, z2;
int ans = -228;
int dist[MAXN][MAXN];
bool used[MAXN];
unsigned int a1[4444 / 32];
unsigned int a2[4444 / 32];
int cnt[(1 << 16) + 10];

int f(int x)
{
	int res = 0;
	while (x)
	{
		res += (x & 1);
		x >>= 1;
	}
	return res;
}

void precalc()
{
	for (unsigned int i = 0; i < (1 << 16) + 10; ++i)
	{
		cnt[i] = f(i);
	}
}

void put(unsigned int *a, int v)
{
	a[v / 32] |= (1 << (v % 32));
}

int calc(int i, int j)
{
	for (int i = 0; i < 4444 / 32; ++i)
	{
		a1[i] = 0;
		a2[i] = 0;
	}
	int v = cur[i].first.first;
	int u = cur[i].first.second;
	put(a1, v);
	while (v != u)
	{
		for (int to : g[v])
		{
			if (dist[v][u] > dist[to][u])
			{
				v = to;
				break;
			}
		}
		put(a1, v);
	}
	v = cur[j].first.first;
	u = cur[j].first.second;
	put(a2, v);
	while (v != u)
	{
		for (int to : g[v])
		{
			if (dist[v][u] > dist[to][u])
			{
				v = to;
				break;
			}
		}
		put(a2, v);
	}
	int res = 0;
	for (int i = 0; i < 4444 / 32; ++i)
	{
		unsigned int z = a1[i] & a2[i];
		res += cnt[z >> 16] + cnt[z & ((1 << 16) - 1)];
	}
	return res;
}

void dfs(int v, int t, int p = 0, int d = 0)
{
	used[v] = 1;
	dist[t][v] = d;
	dist[v][t] = d;
	for (int to : g[v])
	{
		if (to != p)
		{
			dfs(to, t, v, d + 1);
		}
	}
}

signed main()
{
	ios_base::sync_with_stdio(0), cin.tie(0);
	/*freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);*/
	freopen("twopaths.in", "r", stdin);
	freopen("twopaths.out", "w", stdout);

	precalc();
	cin >> n >> k;
	for (int i = 2; i <= n; ++i)
	{
		int p;
		cin >> p;
		g[p].push_back(i);
		g[i].push_back(p);
	}
	for (int i = 1; i <= n; ++i)
	{
		memset(used, 0, sizeof(used));
		dfs(i, i);
	}
	for (int i = 1; i <= k; ++i)
	{
		cin >> cur[i].first.first >> cur[i].first.second;
		cur[i].second = i;
	}
	srand(43 * n + k * 1223);
	random_shuffle(cur + 1, cur + 1 + k);
	for (int i = 1; i <= k; ++i)
	{
		if (i % 32 == 0)
		{
			if (1.0 * clock() / CLOCKS_PER_SEC > 1.96)
			{
				cout << max(0, ans - 1) << '\n';
				cout << z1 << ' ' << z2;
				return 0;
			}
		}
		for (int j = i + 1; j <= k; ++j)
		{
			int d = calc(i, j);
			if (ans < d)
			{
				ans = d;
				z1 = cur[i].second;
				z2 = cur[j].second;
			}
		}
	}
	cout << max(0, ans - 1) << '\n';
	cout << z1 << ' ' << z2;
	return 0;
}