#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <bitset>
#include <cassert>
#include <ciso646>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <deque>
#include <initializer_list>
#include <iostream>
#include <iomanip>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef long double ld;
time_t _timer;

void _pre()
{
	_timer = clock();
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
#ifdef ANDREIKKAA
	assert(freopen("input.txt", "r", stdin) != nullptr);
	//freopen("output.txt", "w", stdout);
#else
	assert(freopen("twopaths.in", "r", stdin) != nullptr);
	assert(freopen("twopaths.out", "w", stdout) != nullptr);
#endif
}

void _post()
{
#ifdef ANDREIKKAA
	cout << "\n\n\nTime: " << (clock() - _timer) / (ld)CLOCKS_PER_SEC << endl;
	while (228);
#endif
}

const int MAX_N = 200 * 1000 + 228;
const int LOG_MAX_N = 19;
vector<int> g[MAX_N];
set<pair<int, int>> p_up[MAX_N], p_dw[MAX_N];
int lft[MAX_N];
pair<int, int> sp[LOG_MAX_N + 1][2 * MAX_N];
int sp_ptr = 0;
int l2[2 * MAX_N];
int dpt[MAX_N];
int p_lca[MAX_N];

int get_lca(int x, int y)
{
	x = lft[x];
	y = lft[y];
	if (x > y)
		swap(x, y);

	int len = l2[y - x + 1];
	return min(sp[len][x], sp[len][y - (1 << len) + 1]).second;
}

void dfs_lca(int v, int d)
{
	dpt[v] = d;
	lft[v] = sp_ptr;
	sp[0][sp_ptr] = { d, v };
	++sp_ptr;
	for (int i : g[v])
	{
		dfs_lca(i, d + 1);
		sp[0][sp_ptr] = { d, v };
		++sp_ptr;
	}
}

int ans = 0;
int ans_a = 1;
int ans_b = 2;

inline void relax(int v, const set<pair<int, int>>::iterator l, const pair<int, int> &i)
{
	if (l->second != i.second)
	{
		//cout << "relaax " << l->second << " " << i.second << endl;
		int lca, cur;
		if (dpt[p_lca[l->second]] != dpt[p_lca[i.second]])
		{
			if (dpt[p_lca[l->second]] > dpt[p_lca[i.second]])
				lca = p_lca[l->second];
			else
				lca = p_lca[i.second];
			cur = dpt[v] - dpt[lca];
		}
		else
		{
			lca = get_lca(sp[0][l->first].second, sp[0][i.first].second);
			cur = dpt[v] + dpt[lca] - (dpt[p_lca[l->second]] << 1);
		}
		if (cur > ans)
		{
			ans = cur;
			ans_a = i.second;
			ans_b = l->second;
		}
	}
}

void mrg(int v, set<pair<int, int>> *s, set<pair<int, int>> *t)
{
	if (s->size() < t->size())
	{
		s->swap(*t);
	}

	if (s->size() == 0)
		return;

	for (const auto &i : *t)
	{
		auto it = s->insert(i).first;
		auto l = it;
		auto r = it;
		
		while (l != s->begin() and l->second == i.second)
			--l;
		relax(v, l, i);
		
		while (r != s->end() and l->second == i.second)
			++r;
		if (r != s->end())
			relax(v, r, i);
	}
}

void dfs_ans(int v, set<pair<int, int>>* s)
{
	//cout << "V " << v << endl;
	for (int i : g[v])
	{
		auto t = new set<pair<int, int>>;
		dfs_ans(i, t);
		mrg(v, s, t);
	}
	mrg(v, s, p_dw + v);
	for (const auto &i : p_up[v])
		s->erase(i);
	//cout << "GG " << v << endl;
}


void _solve()
{
	l2[0] = -1;
	for (int i = 1; i <= (MAX_N << 1); ++i)
	{
		l2[i] = l2[i - 1];
		if ((i & (i - 1)) == 0)
		{
			++l2[i];
		}
	}

	int n, k;
	cin >> n >> k;

	for (int i = 2; i <= n; ++i)
	{
		int x;
		cin >> x;
		g[x].push_back(i);
	}

	dfs_lca(1, 0);
	/*for (int i = 1; i <= n; ++i)
	{
		cout << i << " " << lft[i] << endl;
	}
	for (int i = 0; i < sp_ptr; ++i)
	{
		cout << sp[0][i].first << "," << sp[0][i].second << " ";
	}
	cout << endl;*/
	for (int j = 1; j < LOG_MAX_N; ++j)
	{
		for (int i = 0; i + (1 << j) <= sp_ptr; ++i)
		{
			sp[j][i] = min(sp[j - 1][i], sp[j - 1][i + (1 << (j - 1))]);
			//cout << sp[j][i].first << "," << sp[j][i].second << " ";
		}
		//cout << endl;
	}

	for (int i = 1; i <= k; ++i)
	{
		int a, b;
		cin >> a >> b;

		int anc = get_lca(a, b);
		//cout << a << " " << b << " " << anc << endl;
		p_lca[i] = anc;
		p_up[anc].insert({ lft[b], i });
		p_up[anc].insert({ lft[a], i });
		p_dw[a].insert({ lft[b], i });
		p_dw[b].insert({ lft[a], i });
	}

	auto lol = new set<pair<int, int>>;
	dfs_ans(1, lol);
	cout << ans << endl;
	cout << ans_a << " " << ans_b << endl;
}

int main()
{
	_pre();
	_solve();
	_post();
}