#include <cstdio>
#include <cmath>
#include <vector>

using namespace std;

#define MAXN 500007

int time = 0;
struct G;
struct G {
	int id;
	vector<int> links;
	int parent;
	int depth = -1;

	int tin, tout;
	int first;

	G(int i) :id(i) {}
	G() :id(0) {}
};






int powers[MAXN];
int n, m;
G gs[MAXN];
pair<int, int> pairs[MAXN];

int minId(int a, int b) {
	return gs[a].id > gs[b].id ? b : a;
}
int maxId(int a, int b) {
	return gs[a].id < gs[b].id ? b : a;
}
int minTime(int a, int b) {
	return gs[a].tin == gs[b].tin ? minId(a, b) : gs[a].tin > gs[b].tin ? b : a;
}
int maxTime(int a, int b) {
	return gs[a].tin == gs[b].tin ? maxId(a, b) : gs[a].tin < gs[b].tin ? b : a;
}
int minDepth(int a, int b) {
	return gs[a].depth == gs[b].depth ? minTime(a, b) : gs[a].depth > gs[b].depth ? b : a;
}
int maxDepth(int a, int b) {
	return gs[a].depth == gs[b].depth ? maxTime(a, b) : gs[a].depth < gs[b].depth ? b : a;
}

void dfs(int v, vector<int> &out) {
	if (gs[v].depth != 0) {
		gs[v].depth = gs[gs[v].parent].depth + 1;
	}
	gs[v].tin = time++;
	gs[v].first = out.size();
	out.push_back(v);
	for (unsigned int i=0; i<gs[v].links.size(); i++) {
		dfs(gs[v].links[i], out);
		out.push_back(v);
	}
	gs[v].tout = time++;
}

vector<int> lcaPath;
int lcaSparse[20][MAXN];
int logn;
void lcaPrecalc() {
	dfs(0, lcaPath);
	logn = powers[lcaPath.size()]+1;
	for (unsigned int i=0; i<lcaPath.size(); i++)
		lcaSparse[0][i] = lcaPath[i];
	for (int j=1; j<logn; j++) {
		for (unsigned int i=0; i<lcaPath.size(); i++) {
			if (i+(1<<(j-1)) < lcaPath.size()) {
				lcaSparse[j][i] =
					minDepth(lcaSparse[j-1][i], lcaSparse[j-1][i+(1<<(j-1))]);
			} else {
				lcaSparse[j][i] = lcaSparse[j-1][i];
			}
		}
	}
}

int lca(int xa, int xb) {
	int a = min(gs[xa].first, gs[xb].first);
	int b = max(gs[xa].first, gs[xb].first)+1;
	int pow = powers[b-a];
	return minDepth(lcaSparse[pow][a], lcaSparse[pow][b-(1<<pow)]);
}

int pathLen(int a, int b) {
	int slca = lca(a, b);
	return gs[a].depth + gs[b].depth - gs[slca].depth*2;
}
int calc(pair<int, int> p1, pair<int, int> p2) {
	int a = minTime(p1.first, p1.second);
	int b = maxTime(p1.first, p1.second);
	int c = minTime(p2.first, p2.second);
	int d = maxTime(p2.first, p2.second);
	int res = pathLen(a, b) + pathLen(c, d) - pathLen(a, c) - pathLen(b, d);
	return res < 0 ? 0 : (res >> 1);
}



int main() {
	powers[0] = 0;
	for (int i=1; i<MAXN; i++) {
		powers[i] = powers[i-1];
		if ((1<<(powers[i]+1)) == i) {
			powers[i]++;
		}
	}

	freopen("twopaths.in", "r", stdin);
	freopen("twopaths.out", "w", stdout);

	scanf("%d%d", &n, &m);
	for (int i=0; i<n; i++) {
		gs[i] = G(i);
	}
	gs[0].depth = 0;
	for (int i=1; i<n; i++) {
		int p;
		scanf("%d", &p);
		p--;
		gs[i].parent = p;
		gs[p].links.push_back(i);
	}
	for (int i=0; i<m; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		pairs[i] = make_pair(a-1, b-1);
	}
	lcaPrecalc();

	int bestA = -1, bestB = -1;
	int best = -1;
	for (int i=0; i<m; i++) {
		for (int j=i+1; j<m; j++) {
			pair<int, int> p1 = pairs[i];
			pair<int, int> p2 = pairs[j];
			int t = calc(p1, p2);
			if (t > best) {
				best = t;
				bestA = i;
				bestB = j;
			}
		}
	}

	printf("%d\n%d %d\n", best, bestA+1, bestB+1);
}
