#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 = (int)1e6 + 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 up[MAXN][50];

void u(int v, int p) {
	forn(i, 40) {
		up[v][i] = -1;
	}
	up[v][0] = p;
	forq(i, 1, 40) {
		if (up[v][i - 1] == -1) {
			break;
		}
		up[v][i] = up[up[v][i - 1]][i - 1];
	}
	forn(i, G[v].size()) {
		if (G[v][i] != p) {
			u(G[v][i], v);
		}
	}
}

int t;
pii TIM[MAXN];
int GL[MAXN];

void dfsv(int v, int p, int t1) {
	t++;
	TIM[v].X = t;
	GL[v] = t1;
	forn(i, G[v].size()) {
		if (G[v][i] != p) {
			dfsv(G[v][i], v, t1 + 1);
		}
	}
	t++;
	TIM[v].Y = t;
}

bool ppp(int x, int y) {
	return TIM[x].X <= TIM[y].X && TIM[x].Y >= TIM[y].Y;
}

int lca(int x, int y) {
	if (ppp(x, y)) {
		return x;
	}
	for (int i = 40; i >= 0; --i) {
		if (up[x][i] != -1) {
			if (!ppp(up[x][i], y)) {
				x = up[x][i];
			}
		}
	}
	return up[x][0];
}

vector <vector <pii> > kkk;

int getans(int x, int y) {
	int ans1 = 0, ans2 = 0, ans3 = 0, ans4 = 0;
	if (GL[kkk[x][0].X] > GL[kkk[x][0].Y]) {
		swap(kkk[x][0].X, kkk[x][0].Y);
	}
	if (GL[kkk[y][0].X] > GL[kkk[y][0].Y]) {
		swap(kkk[y][0].X, kkk[y][0].Y);
	}
	int ll = lca(kkk[x][0].Y, kkk[y][0].Y);
	ans1 = min(GL[ll] - GL[kkk[x][0].X], GL[ll] - GL[kkk[y][0].X]);
	if (kkk[y].size() == 2) {
		if (GL[kkk[y][1].X] > GL[kkk[y][1].Y]) {
			swap(kkk[y][1].X, kkk[y][1].Y);
		}
		ll = lca(kkk[x][0].Y, kkk[y][1].Y);
		ans2 = min(GL[ll] - GL[kkk[x][0].X], GL[ll] - GL[kkk[y][1].X]);
	}
	if (kkk[x].size() == 2) {
		if (GL[kkk[x][1].X] > GL[kkk[x][1].Y]) {
			swap(kkk[x][1].X, kkk[x][1].Y);
		}
		ll = lca(kkk[x][1].Y, kkk[y][0].Y);
		ans3 = min(GL[ll] - GL[kkk[x][1].X], GL[ll] - GL[kkk[y][0].X]);
	}
	if (kkk[x].size() == 2 && kkk[y].size() == 2) {
		ll = lca(kkk[x][1].Y, kkk[y][1].Y);
		ans4 = min(GL[ll] - GL[kkk[x][1].X], GL[ll] - GL[kkk[y][1].X]);
	}
	return max(0, ans1) + max(0, ans2) + max(0, ans3) + max(0, ans4);
}

int main() {
	file();
	int n, k, x, y;
	scanf("%d%d", &n, &k);
	G.resize(n);
	forn(i, n - 1) {
		scanf("%d", &x);
		--x;
		G[i + 1].psh(x);
		G[x].psh(i + 1);
	}
	if (n <= -1) {
		vector <vector <vi> > kk(n, vector <vi>(n));
		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(k, n) {
				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);
	}
	else {
		dfsv(0, -1, 0);
		u(0, -1);
		kkk.resize(k);
		forn(i, k) {
			scanf("%d%d", &x, &y);
			--x;
			--y;
			int ll = lca(x, y);
			if (ll == x || ll == y) {
				kkk[i].psh(mk(x, y));
			}
			else {
				kkk[i].psh(mk(x, ll));
				kkk[i].psh(mk(y, ll));
			}
		}
		int ans = -1;
		forn(i, k) {
			forq(j, i + 1, k) {
				int hh = getans(i, j);
				if (ans < hh) {
					ans = hh;
					x = i;
					y = j;
				}
			}
		}
		printf("%d\n%d %d", ans, x + 1, y + 1);
	}
	return 0;
}