/* C_TwoPaths */

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

#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <string>
#include <string.h>
#include <stdio.h>
#include <algorithm>

using namespace std;

#define FOR(i, s, f) for (int i = (s); i < (f); ++i)
#define ROF(i, f, s) for (int i = (f) - 1; i >= (s); --i)
#define forn(i, f) for (int i = 0; i < (f); ++i)
#define rofn(i, f) for (int i = (f) - 1; i >= 0; --i)
#define forit(it, x) for (auto it = (x).begin(); it != (x).end(); ++it)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())

typedef long long ll;
typedef const int cint;
typedef long double ld;
#define pi pair < int, int >
#define vi vector < int >

#define TASK "twopaths"

cint N = 2e5 + 3;
cint LOGN = 20;

int n, k;
int p[N];
pi curier[N];
vector < pi > path[N];
vi g[N];

bool used[N];
map < pi, int > check;

int ttime = 0;
int tin[N], tout[N];

int up[N][LOGN];
int dist[N];

inline void clear_used() { memset(used, 0, sizeof(used)); }

bool dfs(int v, int i);
void count_t(int v);
void count_up();
bool is_parent(int a, int b);
int lca(int a, int b);
void count_dist(int v, int cur_dist);
int find_dist(int u, int v);
int dist_uv(int u, int v);

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

//	cout.precision(30);

	cin >> n >> k;
	forn(i, n - 1)
	{
		cin >> p[i + 2];
		g[i + 2].push_back(p[i + 2]);
		g[p[i + 2]].push_back(i + 2);
	}
	p[1] = 0;

	forn(i, k)
		cin >> curier[i].first >> curier[i].second;

	clear_used();
	count_t(1);
	count_up();

	clear_used();
	count_dist(1, 0);

	int maxx = -1;
	pi ans;
	forn(i, k)
	{
		int u1 = curier[i].first;
		int v1 = curier[i].second;
		int anc1 = lca(u1, v1);

		FOR(j, i + 1, k)
		{
			int u2 = curier[j].first;
			int v2 = curier[j].second;
			int anc2 = lca(u2, v2);

			int anc = lca(anc1, anc2);
			int another = (anc == anc1 ? anc2 : anc1);

			int cur_dist = 0;

			if (anc == anc1 || anc == anc2)
			{
				cur_dist -= 2 * dist[another];
/*
				if (is_parent(u1, v2))
					cur_dist += dist[u1];
				else if (is_parent(v2, u1))
					cur_dist += dist[v2];

				if (is_parent(v1, v2))
					cur_dist += dist[v1];
				else if (is_parent(v2, v1))
					cur_dist += dist[v2];

				if (is_parent(v1, u2))
					cur_dist += dist[v1];
				else if (is_parent(u2, v1))
					cur_dist += dist[u2];

				if (is_parent(u1, u2))
					cur_dist += dist[u1];
				else if (is_parent(u2, u1))
					cur_dist += dist[u2];
*/


				int max1 = 0;
				max1 = max(max1, dist_uv(u1, u2));
				max1 = max(max1, dist_uv(u1, v2));

				int max2 = 0;
				max2 = max(max2, dist_uv(v1, u2));
				max2 = max(max2, dist_uv(v1, v2));

				cur_dist += max1 + max2;
			}

			cur_dist = max(cur_dist, 0);

			if (maxx < cur_dist)
			{
				maxx = cur_dist;
				ans = pi(i + 1, j + 1);
			}
		}
	}
	
	/*forn(i, 4)
	{
		int s, d;
		cin >> s >> d;
		cout << lca(s, d);
	}*/

	cout << maxx << endl;
	cout << ans.first << ' ' << ans.second << endl;


	/*
	forn(i, k)
	{
		memset(used, 0, sizeof(used));
		dfs(curier[i].first, i);
	}

	int maxa = -1;
	pi ans;
	forn(i, k)
	{
		FOR(j, i + 1, k)
		{
			int cnt = 0;

			check.clear();

			forn(q, sz(path[i]))
				check[path[i][q]]++;

			forn(q, sz(path[j]))
				check[path[j][q]]++;

			forit(it, check)
				if (it->second == 2)
					++cnt;

			if (cnt > maxa)
			{
				maxa = cnt;
				ans = pi(i, j);
			}
		}
	}

	cout << maxa << endl;
	cout << ans.first + 1 << ' ' << ans.second + 1 << endl;
	*/

	fclose(stdin);
	fclose(stdout);
	return 0;
}

int dist_uv(int u, int v)
{
	return dist[lca(u, v)];
}

int find_dist(int u, int v)
{
	return dist[v] - dist[u];
}

void count_dist(int v, int cur_dist)
{
	used[v] = true;

	dist[v] = cur_dist;

	for (int to : g[v])
		if (!used[to])
			count_dist(to, cur_dist + 1);
}

bool is_parent(int a, int b)
{
	return (tin[a] <= tin[b] && tout[b] <= tout[a]);
}

void count_up()
{
	up[1][0] = 1;

	FOR(t, 1, LOGN)
	{
		FOR(v, 1, n + 1)
			up[v][t] = up[up[v][t - 1]][t - 1];
	}
}

int lca(int a, int b)
{
	if (is_parent(a, b))
		return a;
	if (is_parent(b, a))
		return b;

	for (int t = LOGN - 1; t >= 0; )
	{
		while (t >= 0 && is_parent(up[a][t], b))
			--t;

		a = up[a][max(t, 0)];
	}

	return a;
}

void count_t(int v)
{
	used[v] = true;

	tin[v] = ++ttime;

	for (int to : g[v])
	{
		if (!used[to])
		{
			up[to][0] = v;
			count_t(to);
		}
	}

	tout[v] = ++ttime;
}

bool dfs(int v, int i)
{
	used[v] = true;

	if (v == curier[i].second)
		return true;

	for (int to : g[v])
	{
		if (!used[to])
		{
			path[i].push_back(pi(min(v, to), max(v, to)));
			if (dfs(to, i))
				return true;
			path[i].pop_back();
		}
	}

	return false;
}
