#include <bits/stdc++.h>

using namespace std;

int h[(int)2e5 + 10];
int p[(int)2e5 + 10];
int tt[(int)2e5 + 10];
int mn[(int)2e5 + 10][18];
int l[(int)2e5 + 10], r[(int)2e5 + 10];
int a[(int)2e5 + 10], b[(int)2e5 + 10], c[(int)2e5 + 10];
vector<int> mas[(int)2e5 + 10], por;

int lca(int a, int b)
{
    int q = min(l[a], l[b]);
    int w = max(r[a], r[b]) + 1;
    int t = tt[w - q];
    int x = mn[q][t];
    int y = mn[w - (1 << t)][t];
    if (h[x] < h[y])
        return x;
    else
        return y;
}

bool pr(int a, int b)
{
    return lca(a, b) == b;
}

void dfs(int v)
{
    por.push_back(v);
    for (int i = 0; i < mas[v].size(); i++)
    {
        dfs(mas[v][i]);
        por.push_back(v);
    }
}

int main()
{
    freopen("twopaths.in", "r", stdin);
    freopen("twopaths.out", "w", stdout);
    int n, k;
    scanf("%d%d", &n, &k);
    h[0] = 0;
    tt[1] = 0;
    for (int i = 2; i <= n; i++)
    {
        tt[i] = tt[i / 2] + 1;
    }
    for (int i = 1; i < n; i++)
    {
        scanf("%d", &p[i]);
        p[i]--;
        mas[p[i]].push_back(i);
        h[i] = h[p[i]] + 1;
    }
    dfs(0);
    int f = por.size();
    for (int i = 0; i < n; i++)
    {
        l[i] = f;
        r[i] = -1;
    }
    for (int i = 0; i < f; i++)
    {
        mn[i][0] = por[i];
        if (l[por[i]] == f)
            l[por[i]] = i;
        r[por[i]] = i;
    }
    for (int j = 1; j < 18; j++)
    {
        for (int i = 0; i + (1 << j) <= f; i++)
        {
            int q = mn[i][j - 1];
            int w = mn[i + (1 << (j - 1))][j - 1];
            if (h[q] < h[w])
                mn[i][j] = q;
            else
                mn[i][j] = w;
        }
    }
    /*
    for (int i = 0; i < f; i++)
    {
        cout << por[i] << " ";
    }
    cout << endl;
    //
    for (int j = 0; j < 18; j++)
    {
        cout << j << " " << (1 << j) << "    ";
        for (int i = 0; i + (1 << j) <= f; i++)
        {
            cout << mn[i][j] << " ";
        }
        cout << endl;
    }
    //
    for (int i = 0; i < n; i++)
    {
        cout << l[i] << " " << r[i] << endl;
    }
    //*/
    p[0] = -1;
    for (int i = 0; i < k; i++)
    {
        scanf("%d%d", &a[i], &b[i]);
        a[i]--;
        b[i]--;
    }
    if (k <= 5000)
    {
        for (int i = 0; i < k; i++)
            c[i] = lca(a[i], b[i]);
        int ans = 0;
        int x = 0, y = 1;
        for (int i = 0; i < k; i++)
        {
            for (int j = i + 1; j < k; j++)
            {
                int d = lca(c[i], c[j]);
                if (c[i] != d && d != c[j])
                    continue;
                int sum = 0;
                if (c[i] == d)
                {
                    if (c[j] == d)
                    {
                        sum += h[lca(a[i], a[j])] - h[d];
                        sum += h[lca(a[i], b[j])] - h[d];
                        sum += h[lca(b[i], a[j])] - h[d];
                        sum += h[lca(b[i], b[j])] - h[d];
                    }
                    else if (pr(b[i], c[j]))
                    {
                        sum += h[lca(b[i], a[j])] - h[c[j]];
                        sum += h[lca(b[i], b[j])] - h[c[j]];
                    }
                    else if (pr(a[i], c[j]))
                    {
                        sum += h[lca(a[i], a[j])] - h[c[j]];
                        sum += h[lca(a[i], b[j])] - h[c[j]];
                    }
                    else
                        continue;
                }
                else
                {
                    if (pr(a[j], c[i]))
                    {
                        sum += h[lca(a[i], a[j])] - h[c[i]];
                        sum += h[lca(b[i], a[j])] - h[c[i]];
                    }
                    else if (pr(b[j], c[i]))
                    {
                        sum += h[lca(a[i], b[j])] - h[c[i]];
                        sum += h[lca(b[i], b[j])] - h[c[i]];
                    }
                    else
                        continue;
                }
                if (sum > ans)
                {
                    ans = sum;
                    x = i;
                    y = j;
                }
            }
        }
        cout << ans << endl << x + 1 << " " << y + 1 << endl;
    }
    return 0;
}
