#include <iostream>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <set>
#include <algorithm>

using namespace std;

const int maxN = 100005;

vector<int> edge[maxN];
int pv[maxN];
int used[maxN];
int hv[maxN];

vector<pair<int, int> > ev;
int fv[maxN];

vector<pair<int, int> > curer;

void dfs1(int v, int h)
{
    hv[v] = h;
    for(int i = 0; i < edge[v].size(); i++) dfs1(edge[v][i], h+1);
}

void dfs2(int v)
{
    fv[v] = ev.size();
    ev.push_back(make_pair(hv[v], v));

    for(int i = 0; i < edge[v].size(); i++)
    {
        dfs2(edge[v][i]);
        ev.push_back(make_pair(hv[v], v));
    }
}

pair<int, int> sp[20][maxN*5];
int lg[maxN*5];

void build()
{
    int n = ev.size();

    int k = 0;
    for(int i = 1; i <= n; i++)
    {
        if(i > (1<<k)) k++;
        lg[i] = k;
    }

    for(int i = 0; i < n; i++) sp[0][i] = ev[i];

    for(int k = 1; k < 20; k++)
    {
        for(int i = 0; i < n; i++)
        {
            sp[k][i] = min(sp[k-1][i], sp[k-1][min(n-1, i+(1<<(k-1)))]);
        }
    }
}

pair<int, int> get_min(int l, int r)
{
    int k = lg[r-l+1];
    return min(sp[k][l], sp[k][r-(1<<k)+1]);
}

int lca(int v, int u)
{
    if(fv[v] > fv[u]) swap(v, u);
    return get_min(fv[v], fv[u]).second;
}

int solve(int v1, int u1, int v2, int u2)
{
    //if(hv[lca(v1, v2)] < hv[lca(v1, u2)]) swap(v2, u2);

    int lca1 = lca(v1, u1);
    int lca2 = lca(v2, u2);

    int lca12 = lca(lca1, lca2);
    if(lca12 != lca1 && lca12 != lca2) return 0;

    if(lca12 == lca2)
    {
        swap(v1, v2);
        swap(u1, u2);
        swap(lca1, lca2);
        lca12 = lca1;
    }

    if(lca(v1, v2) == lca1) swap(v1, u1);

    //cout << v1 << " " << u1 << " " << v2 << " " << u2 << endl;

    int lcav = lca(v1, v2);
    int lcau = lca(v1, u2);

    if(hv[lcav] < hv[lcau])
    {
        swap(v2, u2);
        swap(lcav, lcau);
    }

    if(lcau == lca1)
    {
        lcau = lca(u1, u2);

        return (hv[lcav] - hv[lca1]) + (hv[lcau] - hv[lca1]) + 1;
    }

    return abs(hv[lca(v1, v2)] - hv[lca(v1, u2)]) + 1;

}


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

    iostream::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n, m;
    cin >> n >> m;

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

    for(int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        a--; b--;
        curer.push_back(make_pair(a, b));
    }

    dfs1(0, 0);
    dfs2(0);

    build();

    int ans = -1;
    pair<int, int> p;

    for(int i = 0; i < m; i++)
    {
        for(int k = i+1; k < m; k++)
        {
            int lans = solve(curer[i].first, curer[i].second, curer[k].first, curer[k].second);
            if(lans > ans)
            {
                ans = lans;
                p = make_pair(i, k);
            }
        }
    }

    cout << max(0, ans-1) << endl;
    cout << p.first+1 << " " << p.second+1 << endl;


    return 0;
}

