#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

void print_vector(vector<int> &kek) {
    for (int i=0;i<kek.size();i++) cout<<kek[i]<<" ";
    cout<<endl;
}

int n;
vector<vector<int> > g;
vector<vector<int> > v;
bool visi[100000];
bool get(int f, int s, int ind) {
    visi[f]=true;
    v[ind].push_back(f);
    if (f==s) return true;
    for (int i=0;i<g[f].size();i++) {
        if (!visi[g[f][i]]) {
            if (get(g[f][i],s,ind)) return true;
        }
    }
    v[ind].pop_back();
    return false;
}

int main () {
    for (int i=0;i<100000;i++) visi[i]=false;
    freopen("twopaths.in","r",stdin);
    freopen("twopaths.out","w",stdout);
    int k;
    cin>>n>>k;
    g.resize(n,vector<int> (0));
    for (int i=1;i<n;i++) {
        int par;
        cin>>par;
        par--;
        g[i].push_back(par);
        g[par].push_back(i);
    }
   // vector<vector<int> > temp;
    for (int i=0;i<k;i++) {
        for (int i=0;i<n;i++) visi[i]=false;
        int fir,sec;
        cin>>fir>>sec;
        v.push_back(vector<int> (0,0));
        get(fir-1,sec-1,i);
    }
    for (int i=0;i<k;i++) sort(v[i].begin(),v[i].end());
   // print_vector(v[i]);}
    int i1=0,i2=1;
    int best =0 ;
    for (int i=0;i<k-1;i++) {
        for (int j=i+1;j<k;j++) {
            vector<int> temp;
            set_intersection(v[i].begin(),v[i].end(),v[j].begin(),v[j].end(),back_inserter(temp));
           // cout<<endl;
           // for (int ii=0;ii<temp.size();ii++) cout<<temp[ii]<<" ";
           // cout<<endl;
            if (temp.size()>best) {
                best = temp.size();
                i1=i,i2=j;
            }
        }
    }
    if (best<2) {
        cout<<0<<endl<<"1 2";return 0;
    }
    cout<<best-1<<endl<<i1+1<<" "<<i2+1<<endl;
    return 0;

}
