#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define fi(a, b) for (li i = a; i <= b; ++i)
#define fj(a, b) for (li j = a; j <= b; ++j)
#define size(x) int(x.size())
#define mp make_pair

typedef int li;
typedef pair<li, li> pl;

const int MAXN = 2e5 + 1, LN = 20;

li p[MAXN];
vector<li> graph[MAXN];
bool used[MAXN];
vector<li> et, etd;
li place[MAXN], d, t_in[MAXN], t_out[MAXN], t;
li lg2[MAXN * 2 + 1], depth[MAXN];
pl sparse[MAXN * 2 + 1][LN];
pair<pl, pl> path[MAXN];

inline li dist(li u, li v) {
	return abs(depth[u] - depth[v]);
}
//
//inline void bfs() {
//	li v = 1;
//	li l = 0;
//	vector<li> q;
//	q.push_back(v);
//	while (l < size(q)) {
//		used[q[l]] = 1;
//		fi(0, size(graph[q[l]]) - 1) {
//			if (!used[graph[q[l]][i]]) {
//				q.push_back(graph[q[l]][i]);
//				dis[graph[q[l]][i]] = dis[q[l]] + 1;
//			}
//		}
//		++l;
//	}
//	fi(0, MAXN - 1)
//		used[i] = 0;
//}

inline void dfs(li v) {
	used[v] = 1;
	t_in[v] = ++t;
	depth[v] = ++d;
	fi(0, size(graph[v]) - 1) {
		if (!used[graph[v][i]]) {
			etd.push_back(d);
			et.push_back(v);
			place[v] = size(et) - 1;
			dfs(graph[v][i]);
		}
	}
	etd.push_back(d);
	et.push_back(v);
	place[v] = size(et) - 1;
	--d;
	t_out[v] = ++t;
}

inline void cnt_lg2() {
	fi(0, 20) {
		fj((1 << i), min((1 << (i + 1)) - 1, MAXN * 2))
			lg2[j] = i;
	}
}

inline void make_sparse(li n) {
	fi(0, n - 1)
		sparse[i][0] = mp(etd[i], i);
	fj(1, LN - 1) {
		fi(0, n - 1) {
			if (n >= i + (1 << (j - 1)))
				sparse[i][j] = min(sparse[i][j - 1], sparse[i + (1 << (j - 1))][j - 1]);
			else
				sparse[i][j] = sparse[i][j - 1];
		}
	}
}

inline li rmq(li i, li j) {
	if (i > j)
		swap(i, j);
	li len = lg2[j - i + 1];
	return min(sparse[i][len], sparse[j - (1 << len) + 1][len]).second;
}

inline li lca(li u, li v) {
	return et[rmq(place[u], place[v])];
}

inline li g(pl s, pl w) {
	li v1 = lca(s.first, w.first), v2 = lca(s.first, w.second), v3 = lca(s.second, w.first), v4 = lca(s.second, w.second);
	if (v1 == v4)
		return 0;
	if (v1 != v4) {
		s.second = v4;
		w.second = v4;
	}
	bool fs1, fs2, fw1, fw2;
	fs1 = (dist(s.first, w.first) + dist(s.first, w.second)) == dist(w.first, w.second);
	fs2 = (dist(s.second, w.first) + dist(s.second, w.second)) == dist(w.first, w.second);
	fw1 = (dist(w.first, s.first) + dist(w.first, s.second)) == dist(s.first, s.second);
	fw2 = (dist(w.second, s.first) + dist(w.second, s.second)) == dist(s.first, s.second);
	if (fs1 && fs2)
		return dist(s.first, s.second);
	if (fs1 && fw1)
		return dist(s.first, w.first);
	if (fs1 && fw2)
		return dist(s.first, w.second);
	if (fs2 && fw1)
		return dist(s.second, w.first);
	if (fs2 && fw2)
		return dist(s.second, w.second);
	if (fw1 && fw2)
		return dist(w.first, w.second);
	return 0;
}

inline li f(pl s, pl w) {
	li lcs = lca(s.first, s.second), lcw(lca(w.first, w.second));
	return g(mp(lcs, s.first), mp(lcw, w.first)) + g(mp(lcs, s.first), mp(lcw, w.second)) + g(mp(lcs, s.second), mp(lcw, w.first)) + g(mp(lcs, s.second), mp(lcw, w.second));
}

int main() {
	freopen("twopaths.in", "r", stdin);
	freopen("twopaths.out", "w", stdout);
#ifdef _DEBUG
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif

	li n, k, a;

	cin >> n >> k;

	fi(2, n) {
		cin >> a;
		p[i] = a;
		graph[i].push_back(a);
		graph[a].push_back(i);
	}

	dfs(1);

	cnt_lg2();
	make_sparse(size(et));

	li maxi = 0, mi = 1, mj = 2;

	fi(1, k) {
		cin >> path[i].second.first >> path[i].second.second;
		path[i].first.first = depth[path[i].second.second] + depth[path[i].second.first] - 2 * depth[lca(path[i].second.second, path[i].second.first)];
		path[i].first.second = i;
	}

	sort(path + 1, path + k + 1);
	reverse(path + 1, path + k + 1);

	fi(1, k) {
		if (path[i].first.first <= maxi)
			break;
		fj(i + 1, k) {
			if (path[j].first.first <= maxi)
				break;
			if (f(path[i].second, path[j].second) > maxi) {
				maxi = f(path[i].second, path[j].second);
				mi = path[i].first.second;
				mj = path[j].first.second;
			}
		}
	}

	cout << maxi << "\n" << mi << ' ' << mj;

}