#include <iostream>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <set>
#include <algorithm>

using namespace std;

vector<int> edge[1000];
int pv[1000];

int used[1000];
int v_ans[1000];
int path[1000];

vector<pair<int, int> > curer;

int dfs(int v, int u)
{
    if(used[v]) return v_ans[v];

    used[v] = 1;

    if(v == u) return v_ans[v] = 1;

    v_ans[v] = 0;
    for(int i = 0; i < edge[v].size(); i++)
    {
        if(dfs(edge[v][i], u)) v_ans[v] = 1;
    }
    return v_ans[v];
}

int findPath(int v, int u)
{
    int cnt = 0;
    if(path[v] == 1) cnt++;

    path[v] = 1;

    if(v == u) return cnt;

    int next = -1;
    for(int i = 0; i < edge[v].size(); i++)
    {
        if(dfs(edge[v][i], u)) next = edge[v][i];
    }
    if(next != -1) return cnt + findPath(next, u);

    return cnt + findPath(pv[v], u);
}

int main()
{
    freopen("twopaths.in", "r", stdin);
    freopen("twopaths.out", "w", stdout);

    int n, m;
    cin >> n >> m;

    for(int i = 1; i < n; i++)
    {
        cin >> pv[i];
        pv[i]--;
        edge[pv[i]].push_back(i);
    }

    for(int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        a--; b--;
        curer.push_back(make_pair(a, b));
    }

    int ans = -1;
    pair<int, int> p;

    for(int i = 0; i < m; i++)
    {
        for(int k = i+1; k < m; k++)
        {
            for(int j = 0; j < n; j++) path[j] = 0;

            for(int j = 0; j < n; j++) used[j] = 0;

            findPath(curer[i].first, curer[i].second);

            for(int j = 0; j < n; j++) used[j] = 0;
            int lans = findPath(curer[k].first, curer[k].second);

            if(lans > ans)
            {
                ans = lans;
                p = make_pair(i, k);
            }
        }
    }

    cout << max(0, ans-1) << endl;
    cout << p.first+1 << " " << p.second+1 << endl;


    return 0;
}

