#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;
typedef pair<int, int> p;
vector<vector<int> > g;;
map<p, int> edges;
vector<bool> used;
int cnt;

p get_p(int x, int y) {
    return make_pair(min(x, y), max(x, y));
}

bool dfs(int v, int t, int prev = -1) {
    used[v] = true;
    if (prev != -1) {
        if (edges[get_p(prev, v)] == 1) cnt++;
        edges[get_p(prev, v)] = 1;
    }
    if (v == t) return 1;
    for (auto u : g[v]) {
        if (!used[u] && dfs(u, t, v)) return 1;
    }
    if (prev != -1) {
        if (edges[get_p(prev, v)] == 1 && cnt > 0) cnt--;
        edges[get_p(prev, v)] = 0;
    }
    return 0;
}

int main()
{
    freopen("twopaths.in", "r", stdin);
    freopen("twopaths.out", "w", stdout);
    int n, k;
    cin >> n >> k;
    g.assign(n, vector<int>());
    for (int i = 1; i <= n - 1; i++) {
        int x;
        cin >> x;
        g[x - 1].push_back(i);
        g[i].push_back(x - 1);
    }
    vector<p> ppl;
    for (int i = 0; i < k; i++) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        ppl.push_back(make_pair(x, y));
    }
    int res = 0;
    int a = 1, b = 2;
    for (int i = 0; i < k; i++) {
        for (int j = i + 1; j < k; j++) {
            used.assign(n, false);
            cnt = 0;
            for (int i = 0; i < n; i++) {
                for (auto u : g[i]) edges[get_p(i, u)] = 0;
            }
            dfs(ppl[i].first, ppl[i].second);
           /* for (int i = 0; i < n; i++) {
                for (auto u : g[i]) printf("v = %d, u = %d, %d\n", i, u, edges[get_p(i, u)]);
            }*/
            used.assign(n, false);
            dfs(ppl[j].first, ppl[j].second);
            //printf("i = %d, j = %d, cnt = %d\n", i, j, cnt);
            if (cnt >= res) {
                res = cnt;
                a = i;
                b = j;
            }
        }
    }
    cout << res << "\n";
    cout << a + 1 << " " << b + 1 << "\n";
    return 0;
}
