#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>

using namespace std;

int company[100];
pair <int, int> cour[100];
vector <int> level;
int n, k;

void count_level()
{
    level.assign(n, -1);
    level[0] = 0;
    int i;
    for(i = 0; i < n; i++)
    {
        int now = i, dist = 0;
        while(now != 0)
        {
            now = company[now];
            dist++;
        }
        level[i] = dist;
    }
}

int predok(int a, int b)
{
    if(level[a] > level[b])
        while(level[a] > level[b])
            a = company[a];
    else if(level[b] > level[a])
        while(level[b] > level[a])
            b = company[b];
    while(a != b)
    {
        a = company[a];
        b = company[b];
    }
    return a;
}

int main()
{
    int i;
    cin >> n >> k;
    company[0] = -1;
    for(i = 1; i < n; i++)
    {
        cin >> company[i];
        company[i]--;
    }
    for(i = 0; i < k; i++)
    {
        cin >> cour[i].first >> cour[i].second;
        cour[i].first--;
        cour[i].second--;
    }
    count_level();


    //courier routes
    vector <int> route[n];
    for(i = 0; i < k; i++)
    {
        int pred = predok(cour[i].first, cour[i].second);
        int one = cour[i].first, two = cour[i].second;
        while(one != pred)
        {
            route[one].push_back(i);
            one = company[one];
        }
        while(two != pred)
        {
            route[two].push_back(i);
            two = company[two];
        }
    }


    //go go
    int j, l;
    int cour_inter[k][k];
    for(i = 0; i < k; i++)
        for(j = 0; j < k; j++)
            cour_inter[i][j] = 0;
    for(l = 0; l < n; l++)
    {
        for(i = 0; i < route[l].size(); i++)
        {
            for(j = 0; j < route[l].size(); j++)
            {
                if(i != j)
                {
                    cour_inter[route[l][i]][route[l][j]]++;
                }
            }
        }
    }

    int optimal = 0, max_a = 0, max_b = 1;
    for(i = 0; i < k; i++)
    {
        for(j = 0; j < k; j++)
        {
            if(cour_inter[i][j] > optimal)
            {
                optimal = cour_inter[i][j];
                max_a = i;
                max_b = j;
            }
        }
    }

    cout << optimal << endl;
    cout << max_a + 1 << " " << max_b + 1;
    return 0;
}
