#include <bits/stdc++.h>

using namespace std;

int n;
int up[20][200005];
int height[200005];

int lca(int a, int b)
{
    if(height[a] > height[b])
        swap(a, b);
    for(int st=19;st>=0;st--)
    {
        if(height[b] - height[a] >= 1 << st)
        {
            b = up[st][b];
        }
    }
    if(a == b)
        return a;
    for(int st=19;st>=0;st--)
    {
        if(up[st][a] != up[st][b])
        {
            a = up[st][a];
            b = up[st][b];
        }
    }
    return up[0][a];
}

int next(int l, int a)
{
    if(a == l)
        return -1;
    for(int st=19;st>=0;st--)
    {
        if(height[a] - height[l] > 1 << st)
        {
            a = up[st][a];
        }
    }
    return a;
}

int intlen(int a1, int a2, int b1, int b2)
{
    if(a1 > a2)
        swap(a1, a2);
    if(b1 > b2)
        swap(b1, b2);
    int la = lca(a1, a2);
    int lb = lca(b1, b2);
    int l = lca(la, lb);
    if(l != la && l != lb)
    {
        return 0;
    }
    int na1 = next(l, a1);
    int na2 = next(l, a2);
    int nb1 = next(l, b1);
    int nb2 = next(l, b2);
    int ans = 0;
    if(la == lb)
    {
        if(na1 == nb1)
        {
            ans += height[lca(a1, b1)] - height[l];
        }
        if(na1 == nb2)
        {
            ans += height[lca(a1, b2)] - height[l];
        }
        if(na2 == nb1)
        {
            ans += height[lca(a2, b1)] - height[l];
        }
        if(na2 == nb2)
        {
            ans += height[lca(a2, b2)] - height[l];
        }
        return ans;
    }
    if(l == lb)
    {
        swap(na1, nb1);
        swap(na2, nb2);
        swap(a1, b1);
        swap(a2, b2);
    }
    if(na1 == nb1)
    {
        return -height[lca(a1, b2)] + height[lca(a1, b1)];
    }
    if(na1 == nb2)
    {
        return -height[lca(a1, b1)] + height[lca(a1, b2)];
    }
    if(na2 == nb1)
    {
        return -height[lca(a2, b2)] + height[lca(a2, b1)];
    }
    if(na1 == nb2)
    {
        return -height[lca(a2, b1)] + height[lca(a2, b2)];
    }

}

int main()
{
    ios_base::sync_with_stdio(0);
    freopen("twopaths.in", "r", stdin);
    freopen("twopaths.out", "w", stdout);
    int k;
    cin >> n >> k;
    for(int i=1;i<n;i++)
    {
        int a;
        cin >> a;
        up[0][i] = a-1;
        height[i] = height[a-1] + 1;
    }
    for(int st=1;st<20;st++)
    {
        for(int i=0;i<n;i++)
        {
            up[st][i] = up[st-1][up[st-1][i]];
        }
    }
    vector<pair<int, int> > rt;
    for(int i=0;i<k;i++)
    {
        int a, b;
        cin >> a >> b;
        rt.push_back({a-1, b-1});
    }
    int mx = 0, ma = 0, mb = 1;
    for(int i=0;i<k-1;i++)
    {
        for(int j=i+1;j<k;j++)
        {
            int t = intlen(rt[i].first, rt[i].second, rt[j].first, rt[j].second);
            if(t > mx)
            {
                mx = t;
                ma = i;
                mb = j;
            }
        }
    }
    cout << mx << '\n' << ma+1 << ' ' << mb+1;
    return 0;
}
