#include <stdio.h>
#include <vector>
#include <iostream>
#include <algorithm>
#include <map>
#include <math.h>
#include <string>

using namespace std;

#pragma warning(disable:4996)

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

template<typename TT> struct ST {
	vector<TT> T;
	int s;

	ST() {
		s = 0;
	}

	ST(int n) {
		s = n;
		int d = 1;
		while (d < 2 * n) d <<= 1;
		T.assign(d, mp(0, 0));
	}

	void add(int pos, TT val) {
		add(1, 0, s, pos, val);
	}

	TT ask(int l, int r) {
		return ask(1, 0, s, l, r);
	}

private:

	void add(int v, int l, int r, int pos, TT val) {
		if (r - 1 == l) {
			T[v] = val;
			return;
		}
		int m = (l + r) / 2;
		if (pos < m) {
			add(2 * v, l, m, pos, val);
		}
		else {
			add(2 * v + 1, m, r, pos, val);
		}
		T[v] = max(T[2 * v], T[2 * v + 1]);
	}

	TT ask(int v, int l, int r, int l1, int r1) {
		if (l == l1&&r == r1) {
			return T[v];
		}
		int m = (l + r) / 2;
		if (r1 <= m) {
			return ask(2 * v, l, m, l1, r1);
		}
		if (l1 >= m) {
			return ask(2 & v + 1, m, r, l1, r1);
		}
		return max(ask(2 * v, l, m, l1, m), ask(2 * v + 1, m, r, m, r1));
	}
};

vector<int> g[200200], e[200200], LC;
int d[200200], up[200200][18], n, k;
vector<pair<int, int> >  cour;

void initDepth(int v) {
	for (auto to : g[v]) {
		d[to] = d[v] + 1;
		initDepth(to);
	}
}

void build() {
	for (int i = 1; i < 18; ++i) {
		for (int j = 0; j < n; ++j) {
			up[j][i] = up[up[j][i - 1]][i - 1];
		}
	}
}

int lca(int u, int v) {
	if (d[u] > d[v]) {
		for (int i = 0; i < 18; ++i) {
			if ((d[u] - d[v])&(1 << i)) {
				u = up[u][i];
			}
		}
	}
	else {
		for (int i = 0; i < 18; ++i) {
			if ((d[v] - d[u])&(1 << i)) {
				v = up[v][i];
			}
		}
	}
	if (u == v) return u;
	for (int i = 17; i >= 0; --i) {
		if (up[u][i] != up[v][i]) {
			u = up[u][i];
			v = up[v][i];
		}
	}
	return up[v][0];
}

int ans = 0, ansl = 0, ansr = 1;

void upd(int a, int b) {
	auto A = cour[a], B = cour[b];
	int parA = LC[a], parB = LC[b], parG = lca(parA, parB);
	if (parA != parG&&parB != parG) return;
	int t = max(d[lca(A.x, B.x)] + d[lca(A.y, B.y)], d[lca(A.y, B.x)] + d[lca(A.x, B.y)]);
	t -= 2 * max(d[parA], d[parB]);
	t += abs(d[parA] - d[parB]);
	if (ans < t) {
		ans = t;
		ansl = a;
		ansr = b;
	}
}

void solve() {
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n - 1; ++i) {
		int p;
		scanf("%d", &p);
		g[p - 1].push_back(i + 1);
		up[i + 1][0] = p - 1;
	}
	up[0][0] = 0;
	d[0] = 0;
	initDepth(0);
	build();
	for (int i = 0; i < k; ++i) {
		int a, b;
		scanf("%d%d", &a, &b);
		--a;
		--b;
		int l = lca(a, b);
		cour.push_back(mp(a, b));
		LC.push_back(lca(a, b));
	}
	for (int i = 0; i < k; ++i) {
		for (int j = 0; j < i; ++j) {
			upd(i, j);
		}
	}
	printf("%d\n%d %d", ans, ansl + 1, ansr + 1);
}

int main() {
#pragma comment(linker, "/STACK:536870912")
#ifdef _DEBUG
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#else
	freopen("twopaths.in", "rt", stdin);
	freopen("twopaths.out", "wt", stdout);
#endif
	solve();
	return 0;
}
