#include <iostream>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <cstdlib>

#define ll long long
#define ld long double
#define mp make_pair
#define sz(x) (int) x.size()

using namespace std;

#define TASKNAME "twopaths"

const int N = 2e5 + 123;
const int C = 20;

int n, k;
vector<int> g[N];
int ptr;
int arr[2 * N];
int x1[N];
int x2[N];
int log2z[2 * N];
int h[N];
pair<int, int> sp[2 * N][C];

void build() {
	for (int i = 0; i < 2 * N; i++) {
		sp[i][0] = mp(h[arr[i]], arr[i]);
	}

	for (int j = 1; j < C; j++) {
		for (int i = 0; i + (1 << j) - 1 < 2 * N; i++) {
			sp[i][j] = min(sp[i][j - 1], sp[i + (1 << (j - 1))][j - 1]);
		}
	}
}

pair<int, int> get_min(int l, int r) {
	int j = log2z[r - l + 1];
	return min(sp[l][j], sp[r - (1 << j) + 1][j]);
}

int lca(int u, int v) {
	return get_min(min(x1[u], x1[v]), max(x2[u], x2[v])).second;
}

void dfs(int v) {
	x1[v] = ptr;
	x2[v] = ptr;
	arr[ptr++] = v;
	for (int u : g[v]) {
		h[u] = h[v] + 1;
		dfs(u);
		x2[v] = ptr;
		arr[ptr++] = v;
	}
}

vector<pair<int, int>> paths;

int len(int u1, int v1, int u2, int v2) {
	if (h[v1] > h[u1]) {
		swap(u1, v1);
	}
	if (h[v2] > h[u2]) {
		swap(u2, v2);
	}

	int x = lca(u1, u2);
	int y = h[v1] > h[v2] ? v1 : v2;

	return max(0, h[x] - h[y]);
}

int main() {
	ios::sync_with_stdio(false);
	cout.tie(0);
	cin.tie(0);

#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#else
	if (TASKNAME != "") {
		freopen(TASKNAME ".in", "r", stdin);
		freopen(TASKNAME ".out", "w", stdout);
	}
#endif

	log2z[1] = 0;
	for (int i = 2; i < 2 * N; i++) {
		log2z[i] = log2z[i / 2] + 1;
	}

	cin >> n >> k;

	for (int i = 1; i < n; i++) {
		int p;
		cin >> p;
		p--;
		g[p].push_back(i);
	}

	dfs(0);
	build();

	paths.resize(k);
	for (int i = 0; i < k; i++) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		paths[i].first = x;
		paths[i].second = y;
	}

	if (k <= 5000) {
		int ans = 0;
		int best_i = 0;
		int best_j = 1;

		for (int i = 0; i < k; i++) {
			for (int j = i + 1; j < k; j++) {
				int u1 = paths[i].first;
				int v1 = paths[i].second;
				int u2 = paths[j].first;
				int v2 = paths[j].second;

				int t1 = lca(u1, v1);
				int t2 = lca(u2, v2);

				if ((t1 == u1 || t1 == v1) && (t2 == u2 || t2 == v2)) {
					int cur = len(u1, v1, u2, v2);
					if (cur > ans) {
						ans = cur;
						best_i = i;
						best_j = j;
					}
				}
				else if (t1 == u1 || t1 == v1) {
					{
						int cur = len(u1, v1, u2, t2);
						if (cur > ans) {
							ans = cur;
							best_i = i;
							best_j = j;
						}
					}
					{
						int cur = len(u1, v1, v2, t2);
						if (cur > ans) {
							ans = cur;
							best_i = i;
							best_j = j;
						}
					}
				}
				else if (t2 == u2 || t2 == v2) {
					{
						int cur = len(u1, t1, u2, v2);
						if (cur > ans) {
							ans = cur;
							best_i = i;
							best_j = j;
						}
					}
					{
						int cur = len(v1, t1, u2, v2);
						if (cur > ans) {
							ans = cur;
							best_i = i;
							best_j = j;
						}
					}
				}
				else {
					{
						int cur = len(u1, t1, u2, t2) + len(v1, t1, v2, t2);
						if (cur > ans) {
							ans = cur;
							best_i = i;
							best_j = j;
						}
					}
					{
						int cur = len(v1, t1, u2, t2) + len(u1, t1, v2, t2);
						if (cur > ans) {
							ans = cur;
							best_i = i;
							best_j = j;
						}
					}
				}
			}
		}

		cout << ans << endl;
		cout << best_i + 1 << " " << best_j + 1 << endl;
	}

#ifdef _DEBUG
	while (1);
#endif

	return 0;
}