#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 = 200500;

int besta, bestb, bestval;
vector <vector <int> > g;

int p[MAXN];
int deep[MAXN];
int bestjump[MAXN];
int cour[MAXN];
int n, k;

void dfs(int v, int depth)
{
	deep[v] = depth;

	forn(i, sz(g[v]))
		dfs(g[v][i], depth + 1);
}


void updans(int c1, int c2, int val)
{
	if (val > bestval)
	{
		besta = c1;
		bestb = c2;
		bestval = val;
	}                     
}

void updval(int u, int v, int i)
{
	if (deep[v] < deep[bestjump[u]])
	{
		bestjump[u] = v;
		cour[u] = i;
	}
}

pair <int, int> sol(int v)
{
	int bj = bestjump[v];
	int bc = cour[v];
	
	forn(i, sz(g[v]))
	{
		pair <int, int> loc = sol(g[v][i]);
		int cc = loc.second;
		int cj = loc.first;

		updans(cc, bc, deep[v] - max(deep[cj], deep[bj]));
		if (deep[cj] < deep[bj])
		{
			bj = cj;
			bc = cc;
		}
	}

	return mp(bj, bc);

}

pair <int, int> kek[MAXN];

vector <int> who[MAXN];

void dfs(int v, int pv, int depth)
{
	deep[v] = depth;

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

void go(int u, int v, int c)
{

	if (v == u)
	{
		who[v].pb(c);
		return;
	}
	else
	{
		if (deep[v] < deep[u])
			swap(v, u);
		who[v].pb(c);
		go(p[v], u, c);
	}                      
}

int cnt[5000][5000];

void stup()
{

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

	}

	dfs(0, -1, 0);

	       
	forn(i, k)
	{
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		go(u, v, i);
	}


	forn(i, n)
	{
		forn(j, sz(who[i]))
			forn(k, j)
				cnt[who[i][k]][who[i][j]] = cnt[who[i][j]][who[i][k]]++;
	}


	forn(i, k)
		forn(j, k)
		{
			if (bestval < cnt[i][j])
			{
				bestval = cnt[i][j];
				besta = i;
				bestb = j;
			}
			
		}


	cout << bestval - 1 << '\n' << besta + 1 << ' ' << bestb + 1;

}



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);

	if (n <= 5000)
	{
		stup();
		return 0;
	}

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

	dfs(0, 0);

	forn(i, n)
		bestjump[i] = i;
	forn(i, n)
		cour[i] = -1;

	forn(i, k)
	{
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		if (deep[u] < deep[v])
			swap(u, v);
                
		updans(cour[u], i, deep[u] - max(deep[bestjump[u]], deep[v]));
                updval(u, v, i);
	}

	sol(0);

	cout << bestval << '\n' << besta + 1 << ' ' << bestb + 1;
}