
#include <vector>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <cmath>

#pragma comment (linker, "/STACK:100000000")

using namespace std;

vector < vector < pair <int, int> > > events;
vector <bool> on_path;
vector <bool> used;

bool fill_path(vector < vector <int> >& graph, int v, int f)
{
	used[v] = true;
	bool res = false;

	if (v == f)
	{
		on_path[v] = true;
		return true;
	}

	for (int i = 0; i < int(graph[v].size()); i++)
	{
		int to = graph[v][i];
		
		if (used[to])
			continue;

		res = res || fill_path(graph, to, f);

		if (res)
		{
			on_path[v] = true;
			return true;
		}
	}

	on_path[v] = false;
	return false;
}

void fill_places(vector < vector <int> >& graph, int v, vector <int>& start, vector <int>& finish,
				 int depth)
{
	used[v] = true;

	for (int i = 0; i < int(events[v].size ()); i++)
	{
		int ind = events[v][i].first;
		int t = events[v][i].second;

		if (t == 0)
			start[ind] = depth;
		else
			finish[ind] = depth;
	}

	int path_vertex = -1;

	for (int i = 0; i < int (graph[v].size ()); i++)
	{
		int to = graph[v][i];

		if (used[to])
			continue;

		if (!on_path[to])
			fill_places(graph, to, start, finish, depth);
		else
			path_vertex = to;
	}

	if (path_vertex >= 0)
		fill_places(graph, path_vertex, start, finish, depth + 1);
}

int main()
{
	freopen( "twopaths.in", "r", stdin);
	freopen("twopaths.out", "w", stdout);

	int n = 0, k = 0;
	scanf("%d%d", &n, &k);

	vector < vector <int> > graph(n);
	events = vector < vector < pair <int, int> > > (n);
	on_path = vector <bool>(n, false);
	used = vector <bool>(n, false);

	vector < pair <int, int> > couriers(k);

	for (int i = 1; i < n; i++)
	{
		int parent = 0;
		scanf ("%d", &parent);
		parent--;

		graph[parent].push_back(i);
		graph[i].push_back(parent);
	}

	for (int i = 0; i < k; i++)
	{
		int a = 0, b = 0;
		scanf("%d%d", &a, &b);
		a--; b--;

		events[a].push_back({ i, 0 });
		events[b].push_back({ i, 1 });

		couriers[i] = { a, b };
	}

	int i_max = 0, j_max = 0;
	int max_ans = -1;

	vector <int> start  (k);
	vector <int> finish (k);

	for (int i = 0; i < k; i++)
	{
		on_path = vector <bool>(n, false);	
		start = vector <int>(k);
		finish = vector <int>(k);

		used = vector <bool>(n, false);
		fill_path(graph, couriers[i].first, couriers[i].second);

		used = vector <bool>(n, false);
		fill_places(graph, couriers[i].first, start, finish, 0);

		for (int j = 0; j < k; j++)
		{
			if (i != j)
			{
				int new_ans = abs(finish[j] - start[j]);

				if (abs(finish[j] - start[j]) > max_ans)
				{
					max_ans = new_ans;
					i_max = i;
					j_max = j;
				}
			}
		}
	}
	
	printf("%d\n%d %d", max_ans, i_max + 1, j_max + 1);

	return 0;
}