#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <iterator>
using namespace std;


int G[200][200];
int path[200][200];
bool fnd;

void dfs(int st, int prev, int sr) {
	if (st == sr) {
		fnd = true;
		return;
	}
	for (int i = 0; i < 200; i++) {
		if (G[st][i] == 1 and i != prev) {
			path[st][i] += 1;	
			path[i][st] += 1;
			dfs(i, st, sr);
			if (!fnd) {
				path[st][i] -= 1;	
				path[i][st] -= 1;	
			} else {
				break;
			}
		}
	}
}

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

	int n, m;
	cin >> n >> m;
	for (int i = 0; i < 200; i++) {
		for (int j = 0; j < 200; j++) {
			G[i][j] = 0;
			path[i][j] = 0;
		}
	}
	for (int i = 1; i < n; i++) {
		int tmp;
		cin >> tmp;
		G[tmp-1][i] = 1;
		G[i][tmp-1] = 1;
	}
	vector <pair<int, int> > carry;
	for (int i = 0; i < m; i++) {
		int f, t;
		cin >> f >> t;
		carry.push_back(make_pair(f-1, t-1));
	}

	pair<int, int> answer = make_pair(-1, -1);
	int anss = -1;
	for (int i = 0; i < m; i++) {
		for (int j = i + 1; j < m; j++) {
			// cout  << i << " " << j << "&&&&&&&&" << endl;
			fnd = false;
			dfs(carry[i].first, -1, carry[i].second);
			fnd = false;
			dfs(carry[j].first, -1, carry[j].second);
			int sm = 0;
			for (int x = 0; x < 200; x++) {
				for (int y = 0; y < 200; y++) {
					sm += (path[x][y] == 2);
					// if (path[x][y] == 2) {
						// cout << x << " " << y << endl;
					// }
					path[x][y] = 0;
				}
			}
			if (sm > anss) {
				anss = sm;
				answer = make_pair(i, j);
			}
		}
	}
	cout << anss / 2<< endl << answer.first + 1 << " " << answer.second + 1 << endl;

	fclose(stdin);
	fclose(stdout);
	return 0;
}