#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")

#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <cassert>

using namespace std;

typedef long long ll;

#define TASK "twopaths"
#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define for1(i, n) for(int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define pk push_back
#define mk make_pair

const int MAXN = (int)2e5 + 7;
const int LOG = 17;
const int INF = (int)1e9 + 7;
int solve();

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

struct edge {
	int u, v, num;
};

int n, k, timer;
int p[MAXN], h[MAXN], tin[MAXN], tout[MAXN], lg[MAXN];
int up[MAXN][LOG];
vector<int> g[MAXN];
edge e[MAXN];

void dfs(int v, int pv, int deep) {
	h[v] = deep;
	tin[v] = ++timer;

	up[v][0] = p[v];
	lg[v] = 1;
	for (int j = 1; j < LOG; j++) {
		int pv = up[v][j - 1];
		if (pv) {
			up[v][j] = up[pv][j - 1];
		}
		else {
			lg[v] = j;
			break;
		}
	}

	for (int to : g[v]) {
		if (to != pv){
			dfs(to, v, deep + 1);
		}
	}

	tout[v]= ++timer;
}

int isparent(int u, int v) {
	return u == 0 || tin[u] <= tin[v] && tout[u] >= tout[v];
}

int lca(int u, int v) {
	if (isparent(u, v)) return u;
	if (isparent(v, u)) return v;

	for (int j = lg[v]; j >= 0; j--) {
		int nv = up[v][j];
		if (!isparent(nv, u)) {
			v = nv;
		}
	}
	return p[v];
}

bool cmp(int &u, int &v) {
	return h[u] < h[v];
}

vector<edge> get(int u, int v, int lc) {
	if (lc == u || lc == v) {
		if (h[u] > h[v]) {
			return{ {u, v} };
		}
		else {
			return{ {v, u} };
		}
	}
	return{ {u, lc}, {v, lc} };
}

int cross(edge e1, edge e2) {
	int u1 = e1.u, v1 = e1.v, u2 = e2.u, v2 = e2.v;
	int lc = lca(u1, u2);
	if (h[lc] <= h[v1] || h[lc] <= h[v2]) return 0;
	if (h[v1] > h[v2]) return h[lc] - h[v1];
	return h[lc] - h[v2];
}

int dbl(edge e1, edge e2) {
	int u1 = e1.u, v1 = e1.v, u2 = e2.u, v2 = e2.v;

	int l1 = lca(u1, v1);
	int l2 = lca(u2, v2);

	vector<edge> buf1 = get(u1, v1, l1);
	vector<edge> buf2 = get(u2, v2, l2);
	int ans = 0;
	for (auto ed1 : buf1) {
		for (auto ed2 : buf2) {
			int dt = cross(ed1, ed2);
			ans += dt;
		}
	}
	return ans;
}

vector<int> ord[MAXN];

void sol1() {
	forn(i, k) {
		int u = e[i].u, v = e[i].v;
		if (h[u] > h[v]) {
			swap(u, v);
		}
		ord[v].pk(e[i].num);
	}
	for1(v, n) {
		if (ord[v].size() > 1){
			int num1 = ord[v][0];
			int num2 = ord[v][1];
			if (max(num1, num2) > k) assert(0);
			printf("1\n%d %d", num1, num2);
			return;
		}
	}
	printf("0\n1 2");
}

int solve() {
	cin >> n >> k;
	for (int v = 2; v <= n; v++) {
		scanf("%d", p + v);
		g[p[v]].pk(v);
	}

	forn(i, k) {
		scanf("%d%d", &e[i].u, &e[i].v);
		e[i].num = i + 1;
	}

	dfs(1, 0, 0);

	int busy = 1;
	forn(i, k) {
		int u = e[i].u, v = e[i].v;
		
		if (u != p[v] && v != p[u]) {
			busy = 0;
		}
	}

	if (busy) {
		assert(0);
		sol1();
		return 0;
	}

	int answer = 0, ansu = 1, ansv = 2;
	forn(i, k){
		forn(j, i) {
			int nd = dbl(e[i], e[j]);
			if (nd > answer) {
				answer = nd;
				ansu = e[i].num, ansv = e[j].num;
			}
		}
	}

	printf("%d\n%d %d", answer, ansu, ansv);
	return 0;
}