#include <bits/stdc++.h>
using namespace std;
vector< vector<int> > g;
vector<int> tin, tout;
vector<bool> mark;
int t = 0;

void dfs(int v){
    mark[v] = false;
    tin[v] = t;
    t++;
    for(size_t i = 0; i < g[v].size(); i++){
        int u = g[v][i];
        if(mark[u])
            dfs(u);
    }
    tout[v] = t;
    t++;
}

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

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

    int n, k;
    cin >> n >> k;
    mark.assign(n, true), g.resize(n), tin.resize(n), tout.resize(n);
    vector<int> _p(n);

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

    dfs(0);

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

    int ans = 0, ans_a = 0, ans_b = 1;
    for(int i = 0; i < k; i++){
        for(int j = 0; j < i; j++){
            set<int> z;
            z.insert(path[i].begin(), path[i].end());
            z.insert(path[j].begin(), path[j].end());
            int val = (int) path[i].size() + (int) path[j].size() - (int) z.size();
            if(val > ans){
                ans = val;
                ans_a = i, ans_b = j;
            }
        }
    }

    cout << ans << endl;
    cout << ans_a+1 << " " << ans_b+1 << endl;

    return 0;
}
