#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define sqr(x) (x) * (x)

struct kur
{
    int a, lca, b;
};

const int LEN = 100200, LEN1 = 18;
int n, k, v, t, tin[LEN], tout[LEN], use[LEN], par[LEN1][LEN], res, a, b, h[LEN], hi, use1[LEN], use2[LEN], res1;
vector <int> ed[LEN];
kur ar[LEN];

bool check(int a, int b)
{
    return (tin[a] < tin[b] && tout[a] > tout[b]);
}

void dfs(int v, int p)
{
    use[v] = 1;
    tin[v] = t++;
    h[v] = hi;

    par[0][v] = p;
    for (int i = 1; i < LEN1; i++)
        par[i][v] = par[i - 1][par[i - 1][v]];

    hi++;
    for (int i = 0; i < ed[v].size(); i++)
        if (!use[ed[v][i]])
            dfs(ed[v][i], v);

    hi--;
    tout[v] = t++;
}

int get(int a, int b)
{

    if (a == b || check(a, b))
        return a;
    if (check(b, a))
        return b;

    for (int i = LEN1 - 1; i >= 0; i--)
        if (!check(par[i][a], b))
            a = par[i][a];
    a = par[0][a];

    return a;
}

int getper1(int v, int u, int v1, int u1)
{
    int lca = get(u, u1);
    //cout <<v << " " << v1 << " " << u << " " << u1 << " " << lca << " " << h[lca] << " " << h[v] <<  endl;


    //cout << max(0, h[lca] - max(h[v], h[v1])) << endl;


    return max(0, h[lca] - max(h[v], h[v1]));
}

int getper(int a, int b)
{
    int res = 0;
    res += getper1(ar[a].lca, ar[a].a, ar[b].lca, ar[b].a);
    res += getper1(ar[a].lca, ar[a].a, ar[b].lca, ar[b].b);
    res += getper1(ar[a].lca, ar[a].b, ar[b].lca, ar[b].a);
    res += getper1(ar[a].lca, ar[a].b, ar[b].lca, ar[b].b);

    return res;

}

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

    cin >> n >> k;
    for (int i = 1; i < n; i++)
    {
        //cin >> v;
        scanf("%i", &v);
        v--;
        ed[v].pb(i);
        ed[i].pb(v);
    }

    hi = 0;
    dfs(0, 0);

    for (int i = 0; i < k; i++)
    {
        //cin >> ar[i].a >> ar[i].b;
        scanf("%i %i", &ar[i].a, &ar[i].b);
        ar[i].a--;
        ar[i].b--;

        ar[i].lca = get(ar[i].a, ar[i].b);
    }
    /*
    for (int i = 0; i < k; i++)
        cout << ar[i].lca << " ";
    cout << endl;
    */
    res = -1;
    a = 0;
    b = 1;
    for (int i = 0; i < k; i++)
        for (int j = i + 1; j < k; j++)
        {
            res1 = getper(i, j);
            if (res < res1)
            {
                res = res1;

                //cout << i << " " << j << " " << getper(i, j) << endl;

                a = i;
                b = j;
            }
        }

    cout << res << endl;
    cout << a + 1 << " " << b + 1;

    return 0;
}
/*
4 3
1 2 3
1 4
4 1
1 4
*/
