#include <bits/stdc++.h>

using namespace std;

#define pb push_back

int n,k;
vector<int> v[100005];
vector<int> K[200005];
int vis[100005];

void dfs(int u,int V,int k,int pr,bool &f){
   // cout<<"dfs "<<u<<" "<<V<<endl;
    if(u==V) {f = 1;return;}
    vis[u] = 1;

    for(int i=0;i<v[u].size();i++){

        int Go = v[u][i];


        if(vis[Go] == 1) continue;
        dfs(Go,V,k,u,f);
       // if(u==2) cout<<"u = 2 "<<Go<<" "<<f<<endl;
        //cout<<u<<" "<<V<<" "<<k<<" "<<pr<<" "<<f<<endl;
        if(f) {K[k].pb(max(Go,u)); return;}
    }
    f = 0;
    return;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    freopen("twopaths.in","r",stdin);
    freopen("twopaths.out","w",stdout);
    cin>>n>>k;

    int a,b;


    for(int i=2;i<=n;i++){
        cin>>a;
        v[a].pb(i);
        v[i].pb(a);
    }

/*
    for(int i=0;i<v[2].size();i++)
        cout<<v[2][i]<<" ";
    cout<<endl<<endl;
*/

    bool f = false;

    for(int i=0;i<k;i++){
        cin>>a>>b;
        memset(vis,0,sizeof(vis));
        dfs(a,b,i+1,-1,f);
    }

/*
    cout<<endl;
    for(int i=1;i<=k;i++,cout<<endl)
        for(int j=0;j<K[i].size();j++)
            cout<<K[i][j]<<" ";
    cout<<endl;
    cout<<endl<<endl;*/
    long long mx = -1,ra,rb;

    unordered_set<long long> S;
    long long res = 0;

    for(int i=1;i<=k;i++){

        S.clear();
        for(int q=0;q<K[i].size();q++) S.insert(K[i][q]);

        for(int j=i+1;j<=k;j++){
            res = 0;
            for(int u=0;u<K[j].size();u++)
                if(S.count(K[j][u])) res++;
            if(mx < res) mx = res,ra = i,rb = j;
        }

    }
    cout<<mx<<endl;
    cout<<ra<<" "<<rb;
    return 0;
}
