#include <iostream>
#include <string>
#include <stdio.h>
#include <vector>
using namespace std;

const int maxn = 100005;
vector<int> up;
vector<int> down[maxn];
vector<pair<int, int> > timem;
vector<int> deep;
vector<pair<int, int> > couriers;
vector<int> topc;
int nt = 0, dp = 0;

int dfs(int v)
{
    //cout << v << endl;
    deep[v] = ++dp;
    timem[v].first = ++nt;
    for (int i = 0; i < down[v].size(); ++i) {
        dfs(down[v][i]);
    }
    timem[v].second = ++nt;
    --dp;
}

int pred(int a, int b)
{
    if (timem[a].first <= timem[b].first && timem[a].second >= timem[b].second) {
        return 1;
    }
    /*if (timem[b].first <= timem[a].first && timem[b].second >= timem[a].second) {
        return -1;
    }*/
    return 0;
}

/*int cross(int a, int b, int c, int d)
{
    if (deep[a] > deep[b]) {
        swap(a, b);
    }
    if (deep[c] > deep[d]) {
        swap(c, d);
    }
    if (pred(c, a) && pred(b, d)) {
        return deep[d] - deep[c];
    }
    if (pred(a, c) && pred(d, b)) {
        return deep[b] - deep[a];
    }
    if ()
}*/

int used[maxn];

int main()
{
    freopen("twopaths.in", "r", stdin);
    freopen("twopaths.out", "w", stdout);
    int n, k;
    cin >> n >> k;
    up.resize(n);
    for (int i = 0; i < n - 1; ++i) {
        int t1;
        cin >> t1;
        //cout << "T1 " << t1 << endl;
        --t1;
        down[t1].push_back(i + 1);
        up[i + 1] = t1;
    }
    couriers.resize(k);
    topc.resize(k);
    deep.resize(n);
    timem.resize(n);
    //cout << "!@#" << endl;
    dfs(0);
    //cout << "!@#" << endl;
    for (int i = 0; i < k; ++i) {
        //cout << "!@ee" << endl;
        int t1, t2;
        cin >> t1 >> t2;
        //cout << "T12 " << t1 << " " << t2 << endl;
        --t1;
        --t2;
        //cout << i << endl;
        couriers[i] = make_pair(t1, t2);
        int tp = t1;
        /*while (pred(tp, t2) != 1) {
            tp = up[tp];
        }*/
    }
    int res = -1, cour1, cour2;
    for (int i = 0; i < k - 1; ++i) {
        //cout << "//////////// I = " << i << endl;
        //cout << i << endl;
        for (int j = 0; j < n; ++j) {
            used[j] = 0;
        }
        int t1 = couriers[i].first, t2 = couriers[i].second;
        //cout << "COUR " << couriers[i].first << " " << couriers[i].second << endl;
        int tp1 = t1, tp2 = t2;
        used[t1] = 1;
        used[t2] = 1;
        //cout << t1 << " ";
        while (pred(tp1, t2) != 1) {
            tp1 = up[tp1];
            used[tp1] = 1;
            //cout << tp1 << " ";
        }
        //cout << endl << t2 << " ";
        while (pred(tp2, t1) != 1) {
            tp2 = up[tp2];
            used[tp2] = 1;
            //cout << tp2 << " ";
        }
        //cout << endl;
        for (int j = i + 1; j < k; ++j) {
            //cout << "J = " << j << endl;
            int pres = 0;
            int tj1 = couriers[j].first, tj2 = couriers[j].second;
            int tpj1 = tj1, tpj2 = tj2;
            if (used[tpj1]){
                ++pres;
            }
            if (used[tpj2]) {
                ++pres;
            }
            //cout << "PRES " << pres << endl;
            while (pred(tpj1, tj2) != 1) {
                tpj1 = up[tpj1];
                if (used[tpj1]){
                    ++pres;
                }
                //cout << "PRES " << tpj1 << " " << pres << endl;
            }
            while (pred(tpj2, tj1) != 1) {
                tpj2 = up[tpj2];
                if (used[tpj2]) {
                    ++pres;
                }
                //cout << "PRES " << tpj2 << " " << pres << endl;
            }
            if (used[tpj1]) {
                --pres;
            }
            //cout << "PRES " << pres << endl;
            if (pres > res) {
                res = pres;
                cour1 = i + 1;
                cour2 = j + 1;
            }

        }
        //cout << endl;
    }
    cout << max(0, res - 1) << endl << cour1 << " " << cour2 << endl;
    return 0;
}
