#include <bits/stdc++.h>

using namespace std;

const int maxJumpSize = 17;
vector< vector<int> > jump;
vector<int> depth;

void calcDepth(int u)
{
    if (depth[u] != -1)
        return;

    calcDepth(jump[u][0]);
    depth[u] = depth[jump[u][0]] + 1;
}

int getLCA(int u, int v)
{
    for (int s = maxJumpSize - 1; s >= 0; s--)
        if (depth[jump[u][s]] >= depth[v])
            u = jump[u][s];

    for (int s = maxJumpSize - 1; s >= 0; s--)
        if (depth[jump[v][s]] >= depth[u])
            v = jump[v][s];

    for (int s = maxJumpSize - 1; s >= 0; s--)
    {
        if (jump[u][s] != jump[v][s])
        {
            u = jump[u][s];
            v = jump[v][s];
        }
    }

    if (u != v)
    {
        u = jump[u][0];
        v = jump[v][0];
    }

    return u;
}

int getPathSize(int a, int b, int x, int y)
{
    int SS = 0;
    int L = getLCA(a, x);

    if (depth[L] > depth[b] && depth[L] > depth[y])
        SS = depth[L] - max(depth[b], depth[y]);

    return SS;
}

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

    int n, k;
    cin >> n >> k;

    if (k > 5000)
        return -17;

    jump.resize(n, vector<int>(maxJumpSize));
    jump[0][0] = 0;

    for (int i = 1; i < n; i++)
    {
        cin >> jump[i][0];
        jump[i][0]--;
    }

    depth.resize(n, -1);
    depth[0] = 0;

    for (int i = 0; i < n; i++)
        calcDepth(i);

    for (int s = 1; s < maxJumpSize; s++)
        for (int i = 0; i < n; i++)
            jump[i][s] = jump[jump[i][s - 1]][s - 1];

    vector<int> a(k), b(k);

    for (int i = 0; i < k; i++)
    {
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
    }

    int maxS = 0, currS;
    int mI = 0, mJ = 1;
    int L1, L2;

    for (int i = 0; i < k; i++)
    {
        for (int j = i + 1; j < k; j++)
        {
            L1 = getLCA(a[i], b[i]);
            L2 = getLCA(a[j], b[j]);

            currS = getPathSize(a[i], L1, a[j], L2);
            currS += getPathSize(a[i], L1, b[j], L2);
            currS += getPathSize(b[i], L1, a[j], L2);
            currS += getPathSize(b[i], L1, b[j], L2);

            if (currS >= maxS)
            {
                maxS = currS;
                mI = i;
                mJ = j;
            }
        }
    }

    cout << maxS << '\n';
    cout << mI + 1 << ' ' << mJ + 1;

    return 0;
}
