#include <bits/stdc++.h>
#define TASK "twopaths"

using namespace std;

typedef pair < int , int > ipair;

const int N = 200179;
const int D = 18;

int n, k;
int ansN = 0, ansA = 0, ansB = 1;

struct Person
{
    int dep;
    int up[D];
    ipair maxUp = {0, -1}, maxUp1 = {0, -1};
    vector < int > e;
    vector < int > ht;
} a[N];

struct Crr
{
    int a, b;
} c[N];

void dfs1(int v, int dep = 0)
{
    a[v].dep = dep;
    for (int i = 1; i < D; ++i)
    {
        int prv = a[v].up[i - 1];
        if (prv == -1)
            a[v].up[i] = -1;
        else
            a[v].up[i] = a[prv].up[i - 1];
    }
    for (int nv : a[v].e)
        dfs1(nv, dep + 1);
}

int lcp(int x, int y)
{
    if (a[x].dep < a[y].dep)
        swap(x, y);
    int ost = a[x].dep - a[y].dep;
    for (int d = D - 1; d >= 0; --d)
        if (ost >= (1 << d))
        {
            ost -= (1 << d);
            x = a[x].up[d];
        }
    if (x == y)
        return x;
    for (int d = D - 1; d >= 0; --d)
    {
        int nx = a[x].up[d];
        int ny = a[y].up[d];
        if (nx != ny)
        {
            x = nx;
            y = ny;
        }
    }
    return a[x].up[0];
}

ipair dfs2(int v)
{
    ipair res = a[v].maxUp, res1 = a[v].maxUp1;
    for (int nv : a[v].e)
    {
        ipair q = dfs2(nv);
        if (q.first <= 1)
            q = {0, -1};
        else
            --q.first;
        if (q > res)
        {
            res1 = res;
            res = q;
        } else if (q > res1)
            res1 = q;
    }
    if (res1.first > ansN)
    {
        ansN = res1.first;
        ansA = res.second;
        ansB = res1.second;
    }
    return res;
}

int main()
{
#ifndef LOCAL
    freopen(TASK".in", "r", stdin);
    freopen(TASK".out", "w", stdout);
#endif
    ios::sync_with_stdio(false);

    cin >> n >> k;
    a[0].up[0] = -1;
    for (int i = 1; i < n; ++i)
    {
        cin >> a[i].up[0];
        --a[i].up[0];
        a[a[i].up[0]].e.push_back(i);
    }
    for (int i = 0; i < k; ++i)
    {
        cin >> c[i].a >> c[i].b;
        --c[i].a;
        --c[i].b;
    }

    dfs1(0);
    for (int i = 0; i < k; ++i)
    {
        int ca = c[i].a;
        int cb = c[i].b;
        int p = lcp(ca, cb);
        ipair q;
        q = {a[ca].dep - a[p].dep, i};
        if (q > a[ca].maxUp)
        {
            a[ca].maxUp1 = a[ca].maxUp;
            a[ca].maxUp = q;
        } else if (q > a[ca].maxUp1)
            a[ca].maxUp1 = q;
        q = {a[cb].dep - a[p].dep, i};
        if (q > a[cb].maxUp)
        {
            a[cb].maxUp1 = a[cb].maxUp;
            a[cb].maxUp = q;
        } else if (q > a[cb].maxUp1)
            a[cb].maxUp1 = q;
    }

    dfs2(0);

    cout << ansN << "\n" << ansA + 1 << " " << ansB + 1 << "\n";


    return 0;
}
