#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <vector>
#include <string>
#include <cassert>
#include <utility>
#include <stack>
#include <set>
#include <unordered_set>
#include <functional>

#define ll long long
#define ld long double
#define mp make_pair
#define TASKNAME "twopaths"

using namespace std;

const int MAXLOG = 22;

namespace sol1 {
	vector<vector<int>> g;
	vector <vector<int>> par;
	vector<int> tin, tout, d;

	int timer = 1;

	void dfs(int v) {
		if (v)
			d[v] = d[par[v][0]] + 1;
		tin[v] = timer++;
		for (int l = 1; l < MAXLOG; l++)
			par[v][l] = par[par[v][l - 1]][l - 1];
		for (int to : g[v])
			dfs(to);
		tout[v] = timer++;
	}

	bool upper(int v, int u) {
		return tin[v] <= tin[u] && tout[u] <= tout[v];
	}

	int lca(int v, int u) {
		if (upper(v, u))
			return v;
		if (upper(u, v))
			return u;
		for (int l = MAXLOG - 1; l >= 0; l--) {
			if (!upper(par[v][l], u))
				v = par[v][l];
		}
		return par[v][0];
	}

	void solve() {
		int n, k;
		scanf("%d %d", &n, &k);//cin >> n >> k;
		g.resize(n);
		tin.resize(n);
		tout.resize(n);
		d.resize(n);
		par.resize(n, vector<int>(MAXLOG, 0));
		par[0][0] = 0;
		for (int i = 1; i < n; i++) {
			int p;
			scanf("%d", &p);//cin >> p;
			g[p - 1].push_back(i);
			par[i][0] = p - 1;
		}
		vector<pair<int, int>> a(k);
		vector<int> anc(k);
		dfs(0);
		for (int i = 0; i < k; i++) {
			scanf("%d %d", &a[i].first, &a[i].second);//cin >> a[i].first >> a[i].second;
			a[i].first--;
			a[i].second--;
			anc[i] = lca(a[i].first, a[i].second);
		}
		int ans = 0;
		pair<int, int> ansp = mp(1, 2);
		for (int i = 0; i < k; i++) {
			for (int j = 0; j < k; j++) {
				if (i == j)
					continue;
				int t1 = anc[i];
				int t2 = anc[j];
				int len1 = 0;
				int len2 = 0;
				if (t1 == t2) {
					int lc = lca(a[j].first, a[i].first);
					len1 = d[lc] - d[t2];
					lc = lca(a[j].second, a[i].second);
					len2 = d[lc] - d[t2];
					int lenn1 = len1 + len2;
					len1 = 0;
					len2 = 0;

					lc = lca(a[j].second, a[i].first);
					len1 = d[lc] - d[t2];
					lc = lca(a[j].first, a[i].second);
					len2 = d[lc] - d[t2];
					int lenn2 = len1 + len2;
					int cur = max(lenn1, lenn2);
					if (cur > ans) {
						ans = cur;
						ansp = mp(i + 1, j + 1);
					}
				}
				else if (upper(t1, t2) && upper(t2, a[i].first)) {
					int lc = lca(a[j].first, a[i].first);
					len1 = d[lc] - d[t2];
					lc = lca(a[j].second, a[i].first);
					len2 = d[lc] - d[t2];
					int cur = max(len1, len2);
					if (cur > ans) {
						ans = cur;
						ansp = mp(i + 1, j + 1);
					}
				}
				else if (upper(t1, t2) && upper(t2, a[i].second)) {
					int lc = lca(a[j].first, a[i].second);
					len1 = d[lc] - d[t2];
					lc = lca(a[j].second, a[i].second);
					len2 = d[lc] - d[t2];
					int cur = max(len1, len2);
					if (cur > ans) {
						ans = cur;
						ansp = mp(i + 1, j + 1);
					}
				}
			}
		}
		printf("%d\n%d %d", ans, ansp.first, ansp.second);//cout << ans << endl << ansp.first << " " << ansp.second;
	}
}

namespace sol2 {
	vector<vector<int>> g;
	vector <vector<int>> par;
	vector<vector<int>> mark;
	vector<int> tin, tout, d;

	int timer = 1;

	void dfs1(int v) {
		if (v)
			d[v] = d[par[v][0]] + 1;
		tin[v] = timer++;
		for (int l = 1; l < MAXLOG; l++)
			par[v][l] = par[par[v][l - 1]][l - 1];
		for (int to : g[v])
			dfs1(to);
		tout[v] = timer++;
	}
	
	bool upper(int v, int u) {
		return tin[v] <= tin[u] && tout[u] <= tout[v];
	}

	int lca(int v, int u) {
		if (upper(v, u))
			return v;
		if (upper(u, v))
			return u;
		for (int l = MAXLOG - 1; l >= 0; l--) {
			if (!upper(par[v][l], u))
				v = par[v][l];
		}
		return par[v][0];
	}

	void solve() {
		int n, k;
		scanf("%d %d", &n, &k);//cin >> n >> k;
		g.resize(n);
		mark.resize(n);
		tin.resize(n);
		tout.resize(n);
		d.resize(n);
		par.resize(n, vector<int>(MAXLOG, 0));
		par[0][0] = 0;
		for (int i = 1; i < n; i++) {
			int p;
			scanf("%d", &p);//cin >> p;
			g[p - 1].push_back(i);
			par[i][0] = p - 1;
		}
		vector<pair<int, int>> a(k);
		vector<int> anc(k);
		vector<bool> usei(k, false);
		dfs1(0);
		set<pair<int, int>> ss;
		for (int i = 0; i < k; i++) {
			scanf("%d %d", &a[i].first, &a[i].second);//cin >> a[i].first >> a[i].second;
			a[i].first--;
			a[i].second--;
			if (d[a[i].first] < d[a[i].second])
				swap(a[i].first, a[i].second);
			if (ss.find(a[i]) != ss.end())
				continue;
			usei[i] = true;
			mark[a[i].first].push_back(i);
			mark[a[i].second].push_back(i);
			anc[i] = lca(a[i].first, a[i].second);
		}
		if (count(usei.begin(), usei.end(), true) == 1) {
			int i = 1;
			usei[i] = true;
			mark[a[i].first].push_back(i);
			mark[a[i].second].push_back(i);
			anc[i] = lca(a[i].first, a[i].second);
		}
		int ans = 0;
		pair<int, int> ansp = mp(1, 2);
		for (int i = 0; i < k; i++) {
			if (!usei[i])
				continue;
			int cur = 0;
			for (int v = a[i].first; v != a[i].second; v = par[v][0]) {
				for (int u : mark[v]) {
					if (u == i)
						continue;
					pair<int, int> pp = a[u];
					if (d[pp.first] > d[a[i].first])
						cur = max(cur, d[a[i].first] - d[pp.second]);
					else if (d[pp.second] < d[a[i].second])
						cur = max(cur, d[pp.first] - d[a[i].second]);
					else cur = max(cur, d[pp.first] - d[pp.second]);

				}
			}
			ans = max(ans, cur);
		}
		printf("%d\n%d %d", ans, ansp.first, ansp.second);//cout << ans << endl << ansp.first << " " << ansp.second;
	}
}

int main() {
#ifdef __DEBUG__
	freopen("input.txt", "r", stdin);
	clock_t start = clock();
#else
	freopen(TASKNAME".in", "r", stdin);
	freopen(TASKNAME".out", "w", stdout);
#endif
	srand(time(NULL));

	int n, k;
	cin >> n >> k;
	freopen(TASKNAME".in", "r", stdin);
	if (k > 5000)
		sol2::solve();
	else sol1::solve();

#ifdef __DEBUG__
	cerr << "\nTime: " << (ld)(clock() - start) / (ld)CLOCKS_PER_SEC << endl;
#endif
	return 0;
}