#include<bits/stdc++.h>
using namespace std;
using namespace __gnu_cxx;

#define xx first
#define yy second
typedef long long ll;
typedef pair<int, int> pii;

vector<vector<int>> g;



int tim[(int)1e5+2], p[(int)1e5+2];
bool used[(int)1e5+2];
pii zap[(int)1e5+2];
set<int> vert[(int)1e5+2];

void dfs(int v, int t)
{
    used[v] = 1;
    tim[v] = t;
    for(int i = 0; i < g[v].size(); i++)
    {
        if(!used[g[v][i]])
            dfs(g[v][i], t+1);
    }
    return;
}

void lca(int a, int b, int i)
{
    cout << "  " << a << " " << b << "\n";
    if(tim[a] < tim[b])
        swap(a, b);
    if(tim[a] > tim[b])
    {
        vert[i].insert(a);
        lca(p[a], b, i);
    }
    if(tim[a] == tim[b])
    {
        if(a == b)
        {
            vert[i].insert(a);
            return;
        }
        vert[i].insert(a);
        vert[i].insert(b);
        lca(p[a], p[b], i);
    }
}

int main()
{
    freopen("twopaths.in", "r", stdin);
    freopen("twopaths.out", "w", stdout);
    int n, k;
    cin >> n >> k;
    g.resize(n);
    p[0] = 0;
    for(int i = 1; i < n; i++)
    {
        int c;
        cin >> c;
        c--;
        p[i] = c;
        g[c].push_back(i);
    }
    dfs(0, 0);
    for(int i = 0; i < k; i++)
    {
        int s, f;
        cin >> s >> f;
        s--;
        f--;
        zap[i] = {s, f};
        lca(s, f, i);
        //cout << i << "\n";
    }

    vector<int> per(n);
    int mx = -1, ai, aj;
    for(int i = 0; i < k; i++)
    {
        for(int j = i+1; j < k; j++)
        {
            for(int t = 0; t < n; t++)
                per[t] = -1;
            int siz = 0;
            set_intersection(vert[i].begin(), vert[i].end(), vert[j].begin(), vert[j].end(), per.begin());
            for(int t = 0; t < n; t++)
                if (per[t] != -1)
                    siz++;
            if(siz > mx)
            {
                mx = siz;
                ai = i+1;
                aj = j+1;
            }
        }
    }
    if(mx > 0)
        mx--;
    cout << mx << "\n" << ai << " " << aj << "\n";
    return 0;
}
