#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <ctime>

using namespace std;

//#define int long long
pair <pair <int, int>, int> zap[1000000];
vector <vector <int> > g;
const int L = 19;
const int MAXN = 1e5 + 1;
int pp[MAXN][L];
int tin[MAXN];
int tout[MAXN];
int tt = 0;
int n, k;
int dd[MAXN];
void dfs(int v = 1, int p = 1, int d = 0) {
	dd[v] = d;
	pp[v][0] = p;
	tin[v] = tt++;
	for (auto to : g[v]) {
		dfs(to, v, d + 1);
	}
	tout[v] = tt++;
}
void postr() {
	for (int l = 1; l < L; ++l) {
		for (int i = 1; i <= n; ++i) {
			pp[i][l] = pp[pp[i][l - 1]][l - 1];
		}
	}
}
bool is_upper(int f, int s) {
	return tin[f] <= tin[s] && tout[f] >= tout[s];
}
void upp(int &f, int s) {
	for (int i = L - 1; i >= 0; --i) {
		if (!is_upper(pp[f][i], s)) {
			f = pp[f][i];
		}
	}
}
int lca(int f, int s) {
	if (is_upper(f, s)) swap(f, s);
	upp(f, s);
	if (is_upper(f, s)) return f;
	if (is_upper(s, f)) return s;
	return pp[f][0];
}
int check(int f, int s, int ff, int ss) {
	if (is_upper(f, s)) swap(f, s);
	if (is_upper(ff, ss)) swap(ff, ss);
	int bot = 0;
	if (is_upper(f, ff)) {
		bot = f;
	}
	else if (is_upper(ff, f)) {
		bot = ff;
	}
	else {
		bot = lca(f, ff);
	}
	if (dd[bot] < dd[s] || dd[bot] < dd[s]) {
		return 0;
	}
	int top = 0;
	if (dd[s] > dd[ss]) {
		top = s;
	}
	else {
		top = ss;
	}
	return max(0, dd[bot] - dd[top]);
}
signed main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	freopen("twopaths.in", "r", stdin);
	freopen("twopaths.out", "w", stdout);
	srand(1488);
	int st = clock();
	cin >> n >> k;
	g.resize(n + 1);
	for (int i = 2; i <= n; ++i) {
		int cur;
		cin >> cur;
		g[cur].push_back(i);
	}
	dfs();
	postr();
	for (int i = 1; i <= k; ++i) {
		cin >> zap[i].first.first >> zap[i].first.second;
		if (zap[i].first.second < zap[i].first.first) {
			swap(zap[i].first.first, zap[i].first.second);
		}
		zap[i].second = i;
	}
	random_shuffle(zap + 1, zap + k + 1);
	int ans = 0, ansi = 1, ansj = 2;
	for (int i = 1; i <= k; ++i) {
		for (int j = i + 1; j <= k; ++j) {
			int curr = clock();
			if ((curr - st) * 1.0 / CLOCKS_PER_SEC > 1.95) {
				goto ll;
			}
			int lcaf = lca(zap[i].first.first, zap[i].first.second);
			int lcas = lca(zap[j].first.first, zap[j].first.second);
			vector <pair <int, int> > v;
			v.push_back(make_pair(lcaf, zap[i].first.first));
			v.push_back(make_pair(lcaf, zap[i].first.second));
			v.push_back(make_pair(lcas, zap[j].first.first));
			v.push_back(make_pair(lcas, zap[j].first.second));
			int cur = 0;
			for (int ii = 0; ii < v.size(); ++ii) {
				for (int jj = ii + 1; jj < v.size(); ++jj) {
					cur += check(v[ii].first, v[ii].second, v[jj].first, v[jj].second);
				}
			}
			if (cur > ans) {
				ans = cur;
				ansi = zap[i].second;
				ansj = zap[j].second;
			}
		}
	}
ll:;
	cout << ans << endl;
	cout << ansi << ' ' << ansj << endl;
}