#include <cstdio>
#include <iostream>
#include <cstring>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <bitset>

using namespace std;

vector<int> gr[200500];
int p[400500], t =  0, l[400500], r[400500], p1[400500], tp[1000500], tin[1000500], tout[1000500];
bool bb[400500];

/*void dfs(int v, int par){
    //tp[t] = v;
    //l[v] = t++;
    tin[v] = t++;
    for (int x : gr[v])
        if (x != par)
            dfs(x, v);
    tout[v] = t++;
    /*if (t == 0)
        p[1] = 1;
    else
        p[t] = p[t - 1] + 1;
    bool first = true;
    for (int x : gr[v])
        if (x != par){
            if (!first){
                tp[t] = v;
                t++;
            }
            first = false;
            dfs(x, v);
            tp[t] = v;
            t++;
        }
    //if (first)
    //    l[v] = t;
    //bb[t] = true;
    //if (first){
    tp[t] = v;
    t++;
    //}
    //r[v] = t++;
    //p[t] = p[t - 1];
    //cout << v << " " << l[v] << " " << r[v] << endl;*/
//}

void dfs(int v, int b, bitset<4050> &b1, int par, int f){
    p[v] = par;
    if (v == b){
        while (v != f){
            b1[v] = 1;
            v = p[v];
        }
        b1[f] = 1;
        return;
    }
    for (int x:gr[v])
        if (x != par)
            dfs(x, b, b1, v, f);
}

int tree[800500], mx[800500];
pair<pair<int, int>, int> v[200500], v1[200500];
pair<pair<int, int>, bool> ev[400500];
int num[200500], rnum[200500], lft[200500];
bitset<4050> path[1000];


int main(){
    freopen("twopath.in", "r", stdin);
    freopen("twopath.out", "w", stdout);
    int n, k, a, b;
    cin >> n >> k;
    for (int i = 1; i < n; i++){
        cin >> a;
        a--;
        gr[a].push_back(i);
        gr[i].push_back(a);
    }
    //dfs(0, -1);
    //p1[t] = 0;
    /*for (int i = t - 1; i >= 0; i--)
        if (bb[i])
            p1[i] = p1[i + 1] + 1;
        else
            p1[i] = p1[i + 1];*/
    int l2[k], r2[k];
    for (int y = 0; y < k; y++){
        cin >>  a>> b;
        a--;
        b--;
        dfs(a, b, path[y], -1, a);
    }
    //for (int i = 0; i < t; i++)
    //    cout << tp[i] << " ";
    //cout << endl;
    bitset<4050> b1;
    int ans = 0, res, al = 0, ar = 1;
    for (int i = 0; i < k; i++)
        for (int j = i + 1; j < k; j++){
            b1 = path[i] & path[j];
            res = ((int)b1.count()) - 1;
            if (res > ans){
                al = i;
                ar = j;
                ans = res;
            }
        }
    cout << ans << endl;
    cout << al + 1 << " " << ar + 1 << endl;
    return 0;
}
