#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
const int maxn = 105;
const int maxk = 105;
bool matr[maxk][maxn] = {0};
int par[maxn] ={0};
bool used[maxn] ={0};

int main()
{
    freopen("twopaths.in","r",stdin);
    freopen("twopaths.out","w",stdout);
    int n,k;
    cin >> n >> k;
    for(int i =2; i <= n; ++i )
        cin >> par[i];
    for(int i = 1; i <= k; ++i)
    {
        int l,r;
        cin >> l >> r;
        for(;;)
        {
            if(l == 1)
                break;
            matr[i][l] = true;
            used[l] = true;
            l = par[l];

        }
        for(;;)
        {
            if(r == 1)
                break;
            matr[i][r] = !used[r];
            r = par[r];
        }
    }
    int maxsovp = 0;
    int r1 = 1;
    int r2 = 2;
    for(int i = 1; i <= k; ++i)
        for(int i1 = i+1; i1 <= k; ++i1)
        {
            int sovp = 0;
            for(int x = 2; x <= n; ++x)
                if(matr[i][x] == true && matr[i1][x] == true )
                    ++sovp;
            if(sovp > maxsovp)
            {
                maxsovp = sovp;
                r1 = i;
                r2 = i1;
            }
        }
    cout << maxsovp << '\n' << r1 << ' ' << r2;
    return 0;
}
