#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <ctime>
#include <queue>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef vector < ll > vll;
typedef vector < vll > vvll;
typedef pair < ll, ll > pll;
typedef pair < pll, ll > ppllll;


vvll list;
vll pi;


void bfs(ll i, ll j) {
	pi = vll(list.size(), 0);
	queue < pll > q;
	q.push(pll (i, i));
	vector < char > used(list.size(), 0);
	used[i] = 1;
	while (!q.empty()) {
		pll c = q.front();
		q.pop();
		pi[c.first] = c.second;
		if (c.first == j)
			break;
		for (size_t i = 0; i != list[c.first].size(); ++i)
			if (!used[list[c.first][i]]) {
				q.push(pll(list[c.first][i], c.first));
				used[list[c.first][i]] = 1;
			}
	}
}


int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	freopen("video.in", "r", stdin);
	freopen("video.out", "w", stdout);
#endif // _DEBUG

	ll n, k;
	cin >> n >> k;
	list.resize(n);
	for (size_t i = 1; i != n; ++i) {
		ll in;
		cin >> in;
		list[i].push_back(in - 1);
		list[in - 1].push_back(i);
	}
	vector < pll > kur(k);
	for (size_t i = 0; i != k; ++i) {
		cin >> kur[i].first >> kur[i].second;
		--kur[i].first, --kur[i].second;
	}

	pll ans;
	ll cq = -1;

	for (size_t i = 0; i != k; ++i)
		for (size_t j = i + 1; j != k; ++j) {
			bfs(kur[i].first, kur[i].second);
			set < pll > a;
			ll q = kur[i].second;
			while (q != pi[q])
				a.insert(pll(min(q, pi[q]), max(q, pi[q]))), q = pi[q];
			bfs(kur[j].first, kur[j].second);
			ll cnt = 0;
			q = kur[j].second;
			while (q != pi[q]) {
				if (a.find(pll(min(q, pi[q]), max(q, pi[q]))) != a.end())
					++cnt;
				q = pi[q];
			}
			if (cnt > cq) {
				cq = cnt;
				ans = pll(i, j);
			}
		}

	cout << cq << '\n';
	cout << ans.first + 1 << ' ' << ans.second + 1;
	return 0;
}