#include <bits/stdc++.h>
#define pii pair<int,int>
using namespace std;
const int N=3999;
int deep[N+1],pr[N+1];
bitset<3999> foo[N+1];

int main()
{
    //ios_base::sync_with_stdio(0);
    //ifstream cin("input.txt");
    //ofstream cout("output.txt");
    //ifstream cin("twopaths.in");
    //ofstream cout("twopaths.out");
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    freopen("twopaths.in","r",stdin);
    freopen("twopaths.out","w",stdout);

    int n,k;
    scanf("%d%d",&n,&k);
    map<pii,int> en;
    int cur=0; // EDGES COUNT
    for(int i=1; i<n; i++)
    {
        scanf("%d",&pr[i]);
        pr[i]--;
        en[{i,pr[i]}]=cur;
        en[{pr[i],i}]=cur;
        cur++;
    }
    deep[0]=0;
    for(int i=1; i<n; i++)
        deep[i]=deep[pr[i]]+1;

    for(int i=0; i<k; i++)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        u--,v--;
        while(u!=v)
        {
            if(deep[u]>deep[v])
            {
                foo[i][en[{u,pr[u]}]]=1;
                u=pr[u];
            }
            else
            {
                foo[i][en[{v,pr[v]}]]=1;
                v=pr[v];
            }
        }
    }

    int best=-1,a,b;
    for(int i=0; i<k; i++)
        for(int j=i+1; j<k; j++)
        {
            int ix=(foo[i]&foo[j]).count();
            if(ix>best)
            {
                best=ix;
                a=i;
                b=j;
            }
        }

    printf("%d\n%d %d",best,a+1,b+1);
    return 0;
}
