#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i < n; i++)
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;

const string NAME = "twopaths";
const int MAXN = 5005;

int c2, c1, bestval;
vector <vector <int> > g;  
pair <int, int> cour[MAXN];
int d[MAXN][MAXN];
int n, k;

void check(int i, int j)
{
	int a = cour[i].first;
	int b = cour[i].second;
	int c = cour[j].first;
	int _d = cour[j].second;
	if (bestval < abs(d[a][_d] - d[a][c] + d[b][_d] - d[b][c]))
	{
		bestval = abs(d[a][_d] - d[a][c] + d[b][_d] - d[b][c]);
		c1 = i;
		c2 = j;
        
        }

}

void dfs(int v, int len, int pv, int root)
{
	d[root][v] = len;

	forn(i, sz(g[v]))
		if (pv != g[v][i])
			dfs(g[v][i], len + 1, v, root);
}

int main()
{
#ifndef LOCAL
	freopen((NAME + ".in").c_str(), "rt", stdin);
	freopen((NAME + ".out").c_str(), "wt", stdout);
#endif

	cin >> n >> k;
	g.resize(n);

	forn(i, n - 1)
	{
		int p;
		cin >> p;
		p--;
		g[p].pb(i + 1);
		g[i + 1].pb(p);
	}

	forn(i, n)
		dfs(i, 0, -1, i);

	forn(i, k)
	{
		cin >> cour[i].first >> cour[i].second;
		cour[i].first--;
		cour[i].second--;
	}
	forn(i, k)
		forn(j, k)
			check(i, j);

       	cout << bestval / 2 << '\n' << c1 + 1 << ' ' << c2 + 1;
}