#include <bits/stdc++.h>

using namespace std;

const int LOG = 25, INF = 1e9;

vector<vector<int> > edges, opens, closes;
vector<int> deeps;
vector<pair<int, int> > couriers;
int ans = 0, ansi = 0, ansj = 1;
set<pair<int, int> > opened;

void dfs(int v, int d) {
	deeps[v] = d;

	for (auto to : edges[v]) {
		dfs(to, d + 1);
	}
}

void work(int v) {
	for (int i = 0; i < (int)closes[v].size(); i++) {
		if (opened.begin()->second != closes[v][i]) {
			if (deeps[v] - opened.begin()->first > ans) {
				ans = deeps[v] - opened.begin()->first;
				ansi = opened.begin()->second;
				ansj = closes[v][i];
			}
		} else if ((int)opened.size() > 1) {
			auto tmp = opened.begin();
			tmp++;

			if (deeps[v] - tmp->first > ans) {
				ans = deeps[v] - tmp->first;
				ansi = tmp->second;
				ansj = closes[v][i];
			}
		}

		opened.erase({deeps[couriers[closes[v][i]].first], closes[v][i]});
	}

	for (int i = 0; i < (int)opens[v].size(); i++) {
		opened.insert({deeps[couriers[opens[v][i]].first], opens[v][i]});
	}

	for (auto to : edges[v]) {
		work(to);
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(nullptr);
	cout.tie(nullptr);

	freopen("twopaths.in", "r", stdin);
	freopen("twopaths.out", "w", stdout);

	int n, k;
	cin >> n >> k;

	edges.resize(n);
	deeps.resize(n, -1);
	couriers.resize(k);
	opens.resize(n);
	closes.resize(n);

	for (int i = 1; i < n; i++) {
		int pr;
		cin >> pr;
		pr--;

		edges[pr].push_back(i);
	}

	dfs(0, 0);

	for (int i = 0; i < k; i++) {
		cin >> couriers[i].first >> couriers[i].second;
		couriers[i].first--, couriers[i].second--;

		if (deeps[couriers[i].first] > deeps[couriers[i].second]) swap(couriers[i].first, couriers[i].second);

		opens[couriers[i].first].push_back(i);
		closes[couriers[i].second].push_back(i);
	}

	work(0);

	cout << ans << "\n" << ansi + 1 << " " << ansj + 1 << "\n";
	
	return 0;
}
