#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
#include <cassert>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>

using namespace std;

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define forq(i, q, n) for (int i = int(q); i < int(n); ++i)
#define all(v) v.begin(), v.end()
#define mk make_pair
#define psh push_back
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define X first
#define Y second
#define TASK "twopaths"

typedef long long ll;
typedef vector <int> vi;
typedef pair <int, int> pii;

const int MOD = (int)1e9 + 7;
const int INF = (int)1e9 + 7;
const int MAXN = 5 * (int)1e3 + 7;
const double EPS = 1e-6;

void file() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#else
	freopen(TASK".in", "r", stdin); freopen(TASK".out", "w", stdout);
#endif
}

bool used[MAXN];
int pr[MAXN];
vector <vi> G;

void dfs(int x, int y) {
	used[x] = 1;
	forn(i, G[x].size()) {
		if (!used[G[x][i]]) {
			pr[G[x][i]] = x;
			dfs(G[x][i], y);
		}
	}
}

int main() {
	file();
	int n, k, x, y;
	scanf("%d%d", &n, &k);
	vector <vector <vi> > kk(n, vector <vi>(n));
	G.resize(n);
	forn(i, n - 1) {
		scanf("%d", &x);
		--x;
		G[i + 1].psh(x);
		G[x].psh(i + 1);
	}
	forn(i, k) {
		scanf("%d%d", &x, &y);
		--x;
		--y;
		memset(used, 0, sizeof(bool) * MAXN);
		dfs(x, y);
		while (y != x) {
			kk[min(y, pr[y])][max(y, pr[y])].psh(i);
			y = pr[y];
		}
	}
	vector <vi> kol(k, vi(k, 0));
	forn(i, n) {
		forn(qq, G[i].size()) {
			k = G[i][qq];
			forn(j, kk[i][k].size()) {
				forq(j1, j + 1, kk[i][k].size()) {
					kol[kk[i][k][j]][kk[i][k][j1]]++;
					kol[kk[i][k][j1]][kk[i][k][j]]++;
				}
			}
		}
	}
	int ans = -1;
	forn(i, k) {
		forq(j, i + 1, k) {
			if (ans < kol[i][j]) {
				ans = kol[i][j];
				x = i;
				y = j;
			}
		}
	}
	printf("%d\n%d %d", ans, x + 1, y + 1);
	return 0;
}