#include <iostream>
#include <iomanip>
#include <cstdio>

#include <cassert>
#include <cmath>
#include <algorithm>
#include <utility>

#include <vector>
#include <set>
#include <map>
#include <queue>
#include <bitset>

using std::cin;
using std::cout;
using std::cerr;

using std::max;
using std::min;
using std::abs;

using std::vector;
using std::set;
using std::map;
using std::pair;
using std::bitset;

#define ff first 
#define ss second
#define pb push_back
#define print(x) cerr << (x) << '\n'
#define dbg(a) cerr << #a << " = " << (a) << '\n'
#define dbg2(a, b) cerr << #a << " = " << (a) << " " << #b << " = " << (b) << '\n'
#define dbg3(a, b, c) cerr << #a << " = " << (a) << " " << #b << " = " << (b) << " " << #c << " = " << (c) << '\n'

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

void init() {
	#ifndef LOCAL
	freopen("twopaths.in", "r", stdin);
	freopen("twopaths.out", "w", stdout);
	#endif
	std::iostream::sync_with_stdio(false);
	cout << std::fixed << std::setprecision(10);
	cerr << std::fixed << std::setprecision(10);
}

const int MAXN = 1e5 + 1, MAXK = 1e3 + 1;
bool used[MAXN];
bitset<MAXN> arr[MAXK];
vector<pii> graph[MAXN];
int target;
bool dfs(int v, int c) {
	used[v] = true;
	if (v == target) {
		return true;
	}
	for (auto e : graph[v]) {
		int to = e.ff, num = e.ss;
		if (!used[to]) {
			if (dfs(to, c)) {
				arr[c][num] = 1;
				return true;
			}
		}
	}
	return false;
}

int main() {
	init();

	int n, k;
	cin >> n >> k;
	for (int i = 2; i <= n; ++i) {
		int x;
		cin >> x;
		graph[x].pb({i, i - 1});
		graph[i].pb({x, i - 1});
	}

	for (int t = 1; t <= k; ++t) {
		int a, b;
		cin >> a >> b;
		for (int i = 1; i <= n; ++i)
			used[i] = false;
		target = b;
		dfs(a, t);
	}
	int mx = -1, mxa, mxb;
	for (int i = 1; i <= k; ++i) {
		for (int j = i + 1; j <= k; ++j) {
			int p = (arr[i] & arr[j]).count();
			if (mx < p) {
				mx = p;
				mxa = i, mxb = j;
			}
		}
	}

	cout << mx << '\n' << mxa << ' ' << mxb << '\n';


	return 0;
}