#define _ijps 0
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <set>
#include <vector>
#include <time.h>

using namespace std;

#define name "twopaths"
typedef long long ll;
#define forn(i, n) for(int i = 0; i < n; i++)
#define fornn(i, a, n) for(int i = a; i < n; i++)
#define mk make_pair

const int dd = 1e5 + 7;
const int infi = 1e9 + 7;
const ll inf = 1e18 + 7;

int n, k;
vector<int> P[dd];
vector<int> S;
pair<int, int> D[dd][20];
int H[dd], L[dd], R[dd], Lo2[dd];

void build() {
	fornn(i, 1, dd) {
		Lo2[i] = Lo2[i / 2] + 1;
	}
	fornn(i, 1, dd) {
		Lo2[i]--;
	}
	int n = S.size();
	forn(i, n) {
		D[i][0] = mk(H[S[i]], S[i]);
	}
	for (int i = 1; i < 20; i++) {
		forn(j, n) {
			int c = j + (1 << (i - 1));
			if (c < S.size()) {
				D[j][i] = min(D[j][i - 1], D[c][i - 1]);
			}
		}
	}
}

pair<int, int> getmin(int l, int r) {
	if (l > r)
		swap(l, r);
	int s = Lo2[(r - l + 1)];
	auto t = min(D[l][s], D[r - (1 << s) + 1][s]);
	return t;
}

int lca(int a, int b) {
	auto t = getmin(L[a], R[b]);
	return t.second;
}

void dfs(int v, int h = 0) {
	H[v] = h;
	L[v] = S.size();
	forn(i, P[v].size()) {
		S.push_back(v);
		dfs(P[v][i], h + 1);
	}
	R[v] = S.size();
	S.push_back(v);
}

int dis(int a, int b) {
	int c = lca(a, b);
	return H[a] + H[b] - H[c] * 2;
}

int stmin(int l, int r) {
	int t = infi;
	for (int i = l; i <= r; i++) {
		t = min(t, S[i]);
	}
	return t;
}

void stressMin(){
	while (1) {
		int n = 100;
		S.resize(n);
		forn(i, n) {
			S[i] = rand() % n;
		}
		build();
		forn(i, n) {
			forn(j, i + 1) {
				int a = stmin(j, i);
				int b = getmin(j, i).second;
				if (a != b) {
					int a = stmin(j, i);
					int b = getmin(j, i).second;
					cerr << 1;
				}
			}
		}
	}
}

int per(int al, int ar, int bl, int br) {
	int c = lca(ar, br);
	int w;
	if (H[al] > H[bl]) {
		w = al;
	}
	else {
		w = bl;
	}
	if (lca(c, w) == w) {
		int g = dis(c, w);
		return g;
	}
	return 0;
}

int main() {
	if (_ijps) {
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	}
	else {
		freopen(name".in", "r", stdin);
		freopen(name".out", "w", stdout);
	}
	
	cin >> n >> k;
	forn(i, n - 1) {
		int t;
		scanf("%d", &t);
		t--;
		P[t].push_back(i + 1);
	}
	dfs(0);
	build();
	vector<pair<int, int> > G(k);
	forn(i, k) {
		scanf("%d%d", &G[i].first, &G[i].second);
		G[i].first--;
		G[i].second--;
	}
	int gg = -1;
	int aa, bb;
	forn(i, k) {
		forn(j, i) {
			{
				int a = lca(G[i].first, G[i].second);
				int b = lca(G[j].first, G[j].second);
				int len = per(a, G[i].first, b, G[j].second) + per(a, G[i].first, b, G[j].first) + per(a, G[i].second, b, G[j].second) + per(a, G[i].second, b, G[j].first);

				if (gg < len) {
					gg = len;
					aa = i;
					bb = j;
				}
			}
		}
	}
	cout << gg << '\n' << aa + 1 << ' ' << bb + 1;
}