#include <bits/stdc++.h>

using namespace std;

#define filename "twopaths"

const int N = 1e6;
const int LOGN = 20;

int p[N], h[N];
vector<int> g[N];
vector<char> used;
set<int> path[N];
int buff[N];

void dfs(int v = 0, int H = 0) {
    used[v] = true;
    h[v] = H;
    for (int u : g[v])
        if (!used[u])
            dfs(u, H + 1);
}

int main() {
    ios_base::sync_with_stdio(false);

#ifndef SCHEMTSCHIK
    freopen(filename".in", "r", stdin);
    freopen(filename".out", "w", stdout);
#endif

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

    used.assign(n, false);
    dfs();

    for (int i = 0; i < k; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        path[i].insert(a);
        path[i].insert(b);
       while (a != b)
            if (h[a] > h[b]) {
                a = p[a];
                path[i].insert(a);
            } else {
                b = p[b];
                path[i].insert(b);
            }
    }

    int ansX = 0, ansY = 1, ans = 0;
    for (int i = 0; i < k; i++)
        for (int j = i + 1; j < k; j++) {
            int _ans = int(set_intersection(path[i].begin(), path[i].end(), path[j].begin(), path[j].end(), buff) - buff) - 1;
            if (_ans > ans) {
                ans = _ans;
                ansX = i, ansY = j;
            }
        }

    cout << ans << endl << ansX + 1 << ' ' << ansY + 1 << endl;

    return 0;
}