#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <memory.h>
#define mp make_pair
using namespace std;

const int MAXN = 400001;
const int LG = 22;

int p[MAXN][LG];
int tin[MAXN], tm = 0;
int a[MAXN], b[MAXN], h[MAXN], c[MAXN];
int ans = 0, av1 = 0, av2 = 1;
bool w[MAXN];

int lca(int v1, int v2)
{
	for (int i = LG - 1; i >= 0; i--)
	{
		if (h[v1] >= h[v2] + (1 << i)) v1 = p[v1][i];
		if (h[v2] >= h[v1] + (1 << i)) v2 = p[v2][i];
	}
	if(v1 == v2) return v1;
	for (int i = LG - 1; i >= 0; i--)
	{
		if (p[v1][i] != p[v2][i]) v1 = p[v1][i], v2 = p[v2][i];
	}
	return p[v1][0];
}

void  merg(int v1, int v2, int hv)
{
	int na;
	if (c[v1] != c[v2]) na = hv - max(c[v2], c[v1]);
	else na = hv + h[lca(b[v1], b[v2])] - 2 * c[v1];
	if (na > ans) ans = na, av1 = v1, av2 = v2;
}


struct cmp
{
	bool operator()(int v1, int v2)
	{
		if (c[v1] < c[v2]) return true;
		if (c[v2] > c[v1]) return false;
		if (tin[b[v1]] < tin[b[v2]]) return true;
		if (tin[b[v2]] < tin[b[v1]]) return false;
		return v1 < v2;
	}
};


set <int, cmp> *st[MAXN];
typedef set <int, cmp>::iterator siter;
vector <int> e[MAXN];
vector <int> as[MAXN];
vector <int> cs[MAXN];

void ins(set <int, cmp>* s, int v, int hv)
{
	if (w[v]) return;
	siter it = s->lower_bound(v);
	if (it != s->end()) merg(v, *it, hv);
	if (it != s->begin())
	{
		it--;
		merg(*it, v, hv);
	}
	s->insert(v);
}

void dfstin(int v)
{
	tin[v] = tm++;
	for (int i = 0; i < e[v].size(); i++) dfstin(e[v][i]);
}

void dfs(int v)
{
	int mv = -1;
	for (int i = 0; i < e[v].size(); i++) dfs(e[v][i]);
	if (e[v].size() == 0)
	{
		st[v] = new set <int, cmp>();
	}
	else
	{
		mv = e[v][0];
		for (int i = 1; i < e[v].size(); i++)
		{
			if (st[mv]->size() < st[e[v][i]]->size()) mv = e[v][i];
		}
		st[v] = st[mv];
	}
	for (int i = 0; i < cs[v].size(); i++)
	{
		int u = cs[v][i];
		w[u] = true;
		st[v]->erase(u);
	}
	for (int i = 0; i < e[v].size(); i++)
	{
		int u = e[v][i];
		if (u != mv)
		{
			for (siter it = st[u]->begin(); it != st[u]->end(); it++)
			{
				//ins(st[v], *it, h[v]);
				if (w[*it]) continue;
				for (siter it2 = st[v]->begin(); it2 != st[v]->end(); it2++)
				{
					merg(*it, *it2, h[v]);
				}
				st[v]->insert(*it);
			}
		}
	}
	for (int i = 0; i < as[v].size(); i++) ins(st[v], as[v][i], h[v]);
}

int main()
{
	freopen("twopaths.in", "r", stdin);
	freopen("twopaths.out", "w", stdout);
	ios_base::sync_with_stdio(0);
	int n, k;
	cin >> n >> k;
	p[1][0] = 1;
	for (int j = 1; j < LG; j++) p[1][j] = 1;
	h[1] = 0;
	for (int i = 2; i <= n; i++)
	{
		cin >> p[i][0];
		h[i] = h[p[i][0]] + 1;
		for (int j = 1; j < LG; j++) p[i][j] = p[p[i][j - 1]][j - 1];
		e[p[i][0]].push_back(i);
	}
	memset(w, 0, sizeof(w));
	for (int i = 0; i < k; i++)
	{
		cin >> a[i] >> b[i];
		a[i + k] = b[i], b[i + k] = a[i];
		int lc = lca(a[i], b[i]);
		c[i] = c[i + k] = h[lc];
		as[a[i]].push_back(i);
		as[b[i]].push_back(i + k);
		cs[lc].push_back(i);
		cs[lc].push_back(i + k);
	}
/*	dfstin(1);
	dfs(1)*/
	for (int i = 0; i < 2 * k; i++)
	{
		for (int j = i + 1; j < 2 * k; j++)
		{
			int a1 = a[i], a2 = a[j];
			int da = lca(a1, a2);
			if ((c[i] < da) && (c[j] < da)) merg(i, j, h[da]);
		}
	}
	cout << ans << endl << av1 % k + 1 << " " << av2 % k + 1 << endl;
	return 0;
}