#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 = 200200, LEN1 = 20;
int n, k, v, t, tin[LEN], tout[LEN], use[LEN], par[LEN1][LEN], res, a, b, h[LEN], hi, use1[LEN], use2[LEN];
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 (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 lca, int v, int u)
{
    if (!check(v, u) && !check(u, v))
        return 0;
    if (!check(v, u))
        swap(v, u);

    return h[v] - h[lca];
}

int getper(int a, int b)
{
    int res = 0, v, u, lca;

    for (int i = 0; i < n; i++)
        use1[i] = use2[i] = 0;

    use1[ar[a].lca] = 1;
    use2[ar[b].lca] = 1;

    v = ar[a].a;
    while (v != ar[a].lca)
    {
        use1[v] = 1;
        v = par[0][v];
    }
    v = ar[a].b;
    while(v != ar[a].lca)
    {
        use1[v] = 1;
        v = par[0][v];
    }


    v = ar[b].a;
    while (v != ar[b].lca)
    {
        use2[v] = 1;
        v = par[0][v];
    }
    v = ar[b].b;
    while(v != ar[b].lca)
    {
        use2[v] = 1;
        v = par[0][v];
    }
    /*
    for (int i = 0; i < n; i++)
    {
        cout << use1[i] << " " << use2[i] << endl;
    }
    */
    for (int i = 0; i < n; i++)
        res += int(use1[i] == 1 && use2[i] == 1);

    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;
        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;
        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++)
            if (res < getper(i, j))
            {
                res = getper(i, j);
                a = i;
                b = j;
            }

    cout << max(0, res - 1) << endl;
    cout << a + 1 << " " << b + 1;

    return 0;
}
