/* 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;

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

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

bool dfs(int v, int i);

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;

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

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