#include <stdio.h>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>

using namespace std;

int n;
vector<int> a;

int pred(int x, int y){
    vector<int> color(n);
    while (true){
        if (color[x] == 2){
            return x;
        }
        if (color[y] == 1){
            return y;
        }
        if (x == y){
            return x;
        }
        color[x] = 1;
        color[y] = 2;
        x = a[x];
        y = a[y];
    }
}

int main(){
    ifstream cin("twopaths.in");
    ofstream cout("twopaths.out");

    int k;
    cin>>n>>k;
    a.resize(n);
    vector<int> g(n);
    a[0] = 0;
    g[0] = 0;
    for (int i = 1; i < n; i++){
        cin>>a[i];
        a[i]--;
        g[i] = g[a[i]] + 1;
    }

    vector<int> x(k);
    vector<int> y(k);
    vector<int> xy(k);

    for (int i = 0; i < k; i++){
        cin>>x[i]>>y[i];
        x[i]--;
        y[i]--;
        xy[i] = pred(x[i], y[i]);
    }

    int maxi = 0;
    int maxj = 1;
    int maxk = 0;
    for (int i = 0; i < k; i++){
        for (int j = i+1; j < k; j++){
            int nacha = pred(xy[i], xy[j]);
            if (nacha == xy[i] || nacha == xy[j]){
                int gn = max(g[xy[i]], g[xy[j]]);
                int out = 0;
                out += min(0, pred(x[i], x[j])-gn);
                out += min(0, pred(y[i], x[j])-gn);
                out += min(0, pred(x[i], y[j])-gn);
                out += min(0, pred(y[i], y[j])-gn);
            }
        }
    }
    cout<<maxk<<"\n"<<maxi+1<<" "<<maxj+1;
}
