#include <bits/stdc++.h>

using namespace std;

const int MX_SZ = 1e+5 + 42;
const int MX_LOG = 17;
const int MX_K = 5042;
vector<int> g[MX_SZ];
int pr[MX_SZ][MX_LOG];
int tin[MX_SZ], tout[MX_SZ], timer = 1;
int h[MX_SZ];

void dfs_pre(int v, int p, int ch)
{
    h[v] = ch;
    tin[v] = timer;
    timer++;
    pr[v][0] = p;
    for (int i = 1; i < MX_LOG; i++)
    {
        pr[v][i] = pr[pr[v][i - 1]][i - 1];
    }
    for (int u : g[v])
    {
        if (u != p)
        {
            dfs_pre(u, v, ch + 1);
        }
    }
    tout[v] = timer;
    timer++;
}

inline bool upper(int v, int u)
{
    return tin[v] < tin[u] and tout[v] > tout[u];
}

inline int get_lca(int v, int u)
{
    if (v == u)
    {
        return v;
    }
    if (upper(v, u))
    {
        return v;
    }
    if (upper(u, v))
    {
        return u;
    }
    for (int i = MX_LOG - 1; i >= 0; i--)
    {
        if (!upper(pr[v][i], u))
        {
            v = pr[v][i];
        }
    }
    return pr[v][0];
}

inline int dist(int v, int u)
{
    return abs(h[v] - h[u]);
}

int main()
{
    freopen("twopaths.in", "r", stdin);
    freopen("twopaths.out", "w", stdout);
    ios_base::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    for (int i = 2; i <= n; i++)
    {
        int anc;
        cin >> anc;
        g[i].push_back(anc);
        g[anc].push_back(i);
    }
    dfs_pre(1, 1, 1);
    static pair<int, int> a[MX_SZ];
    for (int i = 1; i <= k; i++)
    {
        cin >> a[i].first >> a[i].second;
        if (tin[a[i].second] < tin[a[i].first])
        {
            swap(a[i].first, a[i].second);
        }
    }
    int ans = 0;
    pair<int, int> res = {1, 2};
    //random_shuffle(a + 1, a + k + 1);
    for (int i = 1; i <= k; i++)
    {
        for (int j = 1; j <= k; j++)
        {
            if (i == j)
            {
                continue;
            }
            int l1 = get_lca(a[i].first, a[i].second), l2 = get_lca(a[j].first, a[j].second);
            if (l1 == l2)
            {
                int l3 = get_lca(a[i].first, a[j].first), l4 = get_lca(a[i].second, a[j].second);
                int cans = dist(l3, l1) + dist(l4, l1);
                if (ans < cans)
                {
                    ans = cans;
                    res = {i, j};
                }
            }
            else if (upper(l1, l2))
            {
                if (upper(l2, a[i].first))
                {
                    int l5 = get_lca(a[j].first, a[i].first);
                    if (l5 != l2)
                    {
                        int cans = dist(l5, l2);
                        if (ans < cans)
                        {
                            ans = cans;
                            res = {i, j};
                        }
                    }
                    else
                    {
                        l5 = get_lca(a[j].second, a[i].first);
                        int cans = dist(l5, l2);
                        if (ans < cans)
                        {
                            ans = cans;
                            res = {i, j};
                        }
                    }
                }
                else if (upper(l2, a[i].second))
                {
                    int l5 = get_lca(a[j].first, a[i].second);
                    if (l5 != l2)
                    {
                        int cans = dist(l5, l2);
                        if (ans < cans)
                        {
                            ans = cans;
                            res = {i, j};
                        }
                    }
                    else
                    {
                        l5 = get_lca(a[j].second, a[i].second);
                        int cans = dist(l5, l2);
                        if (ans < cans)
                        {
                            ans = cans;
                            res = {i, j};
                        }
                    }
                }
            }
        }
        if (clock() / (double)CLOCKS_PER_SEC > 1.94)
        {
            break;
        }
    }
    cout << ans << endl;
    cout << res.first << " " << res.second << endl;
}
