#include <iostream>
#include <fstream>
#include <set>
#include <algorithm>
#include <stack>
#include <iomanip>
#include <vector>

using namespace std;
int n, k, p[200001], a[200001], b[200001], par[200001], ch[200001], Time = 1, p1[200001], was[200001];
stack <int> s[200001], s1[200001];

void dfs(int v){
    stack <int> s2 = s1[v];
    p1[v] = Time;
    if (v != 1){
        par[Time] = p1[p[v]];
        s[par[Time]].push(Time);
    }
    ch[Time] = 1;
    Time++;
    while (!s2.empty()){
        int u = s2.top();
        s2.pop();
        dfs(u);
        ch[p1[v]] += ch[p1[u]];
    }
    return;
}

int main()
{
    freopen("twopaths.in", "r", stdin);
    freopen("twopaths.out", "w", stdout);
    cin >> n >> k;
    for (int i = 2; i <= n; i++){
        cin >> p[i];
        s1[p[i]].push(i);
    }
    dfs(1);
    for (int i = 1; i <= k; i++){
        cin >> a[i] >> b[i];
        a[i] = p1[a[i]];
        b[i] = p1[b[i]];
    }
    /*
    for (int i = 1; i <= n; i++){
        stack <int> s2 = s[i];
        cout << i << ' ';
        while (!s2.empty()){
            cout << s2.top() << ' ';
            s2.pop();
        }
        cout << endl;
    }
    for (int i = 1; i <= k; i++)
        cout << a[i] << ' ' << b[i] << endl;
    */
    int ans = -1, maxa, maxb;
    par[1] = 0;
    for (int i = 1; i <= k; i++)
    for (int j = i + 1; j <= k; j++){
        for (int l = 1; l <= n; l++)
            was[l] = 0;
        int t = a[i];
        while (t != 0){
            was[t] = 1;
            t = par[t];
        }
        t = b[i];
        while (t != 0){
            was[t] = 1 - was[t];
            t = par[t];
        }
        int sum = 0;
        t = a[j];
        while (t != 0){
            if (was[t] == 1){
                sum++;
                was[t] = 2;
            }
            t = par[t];
        }
        t = b[j];
        while (t != 0){
            if (was[t] == 1)
                sum++;
            if (was[t] == 2)
                sum--;
            t = par[t];
        }
        if (sum > ans){
            ans = sum;
            maxa = i;
            maxb = j;
        }
        //cout << i << ' ' << j << ' ' << sum << endl;
    }
    cout << ans << endl << maxa << ' ' << maxb << endl;
    return 0;
}
