#include <bits/stdc++.h>

using namespace std;

int h[(int)2e5 + 10];
int p[(int)2e5 + 10][21];
int a[5010], b[5010], c[5010];
map<pair<int, int>, int> m;

int lca(int a, int b)
{
    pair<int, int> p = {a, b};
    if (m.count(p))
        return m[p];
    if (h[a] < h[b])
        swap(a, b);
    if (h[a] > h[b])
    {
        for (int i = 20; i >= 0; i--)
        {
            if ((1 << i) <= h[a] - h[b])
            {
                a = p[a][i];
            }
        }
    }
    if (a != b)
    {
        for (int i = 20; i >= 0; i--)
        {
            if (p[a][i] != p[b][i])
            {
                a = p[a][i];
                b = p[b][i];
            }
        }
        return m[p] = p[a][0];
    }
    return m[p] = a;
}

bool pr(int a, int b)
{
    if (h[a] >= h[b])
    {
        for (int i = 20; i >= 0; i--)
        {
            if ((1 << i) <= h[a] - h[b])
                a = p[a][i];
        }
        return (a == b);
    }
    else
        return false;
}

bool kek(int a, int b)
{
    if (h[a] >= h[b])
        return pr(a, b);
    else
        return pr(b, a);
}

int main()
{
    freopen("twopaths.in", "r", stdin);
    freopen("twopaths.out", "w", stdout);
    int n, k;
    scanf("%d%d", &n, &k);
    h[0] = 0;
    for (int i = 1; i < n; i++)
    {
        scanf("%d", &p[i][0]);
        p[i][0]--;
        h[i] = h[p[i][0]] + 1;
    }
    p[0][0] = 0;
    for (int j = 0; j < 20; j++)
    {
        for (int i = 0; i < n; i++)
        {
            p[i][j + 1] = p[p[i][j]][j];
        }
    }
    for (int i = 0; i < k; i++)
    {
        scanf("%d%d", &a[i], &b[i]);
        a[i]--;
        b[i]--;
        c[i] = lca(a[i], b[i]);
    }
    if (k <= 5000)
    {
        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;
}
