#include <bits/stdc++.h>

using namespace std;

const int MX_SZ = 4042;
vector<int> g[MX_SZ];
int p[MX_SZ];
bool used[MX_SZ];

void dfs(int v)
{
    used[v] = true;
    for (int u : g[v])
    {
        if (!used[u])
        {
            p[u] = v;
            dfs(u);
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    freopen("twopaths.in", "r", stdin);
    freopen("twopaths.out", "w", stdout);
    int n, m;
    cin >> n >> m;
    for (int i = 2; i <= n; i++)
    {
        int t;
        cin >> t;
        g[t].push_back(i);
        g[i].push_back(t);
    }
    static pair<int, int> a[MX_SZ];
    static set<pair<int, int>> st[MX_SZ];
    for (int i = 0; i < m; i++)
    {
        cin >> a[i].first >> a[i].second;
        memset(used, false, sizeof(used));
        dfs(a[i].first);
        int v = a[i].second;
        while (v != a[i].first)
        {
            int u = p[v];
            st[i].insert(make_pair(min(v, u), max(v, u)));
            v = u;
        }
    }
    int ans = 0;
    pair<int, int> res = {1, 2};
    for (int i = 0; i < m; i++)
    {
        for (int j = i + 1; j < m; j++)
        {
            int cans = 0;
            for (auto k : st[i])
            {
                if (st[j].find(k) != st[j].end())
                {
                    cans++;
                }
            }
            if (cans > ans)
            {
                ans = cans;
                res = {i + 1, j + 1};
            }
        }
    }
    cout << ans << endl;
    cout << res.first << " " << res.second << endl;
}
