#include <bits/stdc++.h>

#define TASK "twopaths"
using namespace std;
typedef int ll;
typedef long double ld;

ll n, k;
ll p[100000];
ll h[100000];
vector<ll> predk[100000];
map<ll, vector<ll>> potoms[100000];
//ll cntnow[50000];

inline void dfs0(ll v, ll len)
{
    h[v] = len;
    for (auto i : potoms[v])
    {
        dfs0(i.first, len + 1);
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    if(strcmp(TASK,"")!=0)
    {
        freopen(TASK".in","r",stdin);
        freopen(TASK".out","w",stdout);
    }
#endif
    scanf("%d%d", &n, &k);
    //cin >> n >> k;
    for (int i = 1; i < n; i++)
    {
        ll val;
        scanf("%d", &val);
        //cin >> val;
        p[i] = val - 1;
        potoms[val - 1][i] = vector<ll>();
    }
    dfs0(0, 0);
    ll ans = 0;
    ll a1, a2;
    for (int i = 0; i < k; i++)
    {
        ll a, b;
        scanf("%d%d", &a, &b);
        //cin >> a >> b;
        ll aa = a;
        ll bb = b;
        aa--;
        bb--;
        unordered_map<ll, ll> cntnow;
        cntnow.rehash(56789);
        //memset(cntnow,0,sizeof(cntnow));
        a--;
        b--;
        ll cnt = 0;
        while (a != b)
        {
            cnt++;
            if (h[a] >= h[b])
            {
                //predk[a].push_back(i);
                //potoms[p[a]][a].push_back(i);
                a = p[a];
            }
            else
            {
                //predk[b].push_back(i);
                //potoms[p[b]][b].push_back(i);
                b = p[b];
            }
        }
        if (cnt > ans)
        {
            a = aa;
            b = bb;
            while (a != b)
            {
                if (h[a] >= h[b])
                {
                    for (auto j : predk[a])
                    {
                        if (cntnow.find(j) != cntnow.end())
                            cntnow[j]++;
                        else cntnow[j] = 1;
                        if (cntnow[j] > ans)
                        {
                            ans = cntnow[j];
                            a1 = j;
                            a2 = i;
                        }
                    }
                    predk[a].push_back(i);
                    potoms[p[a]][a].push_back(i);
                    a = p[a];
                }
                else
                {
                    for (auto j : predk[b])
                    {
                        if (cntnow.find(j) != cntnow.end())
                            cntnow[j]++;
                        else cntnow[j] = 1;
                        if (cntnow[j] > ans)
                        {
                            ans = cntnow[j];
                            a1 = j;
                            a2 = i;
                        }
                    }
                    predk[b].push_back(i);
                    potoms[p[b]][b].push_back(i);
                    b = p[b];
                }
            }
        }
        else
        {
            a = aa;
            b = bb;
            while (a != b)
            {
                cnt++;
                if (h[a] >= h[b])
                {
                    predk[a].push_back(i);
                    potoms[p[a]][a].push_back(i);
                    a = p[a];
                }
                else
                {
                    predk[b].push_back(i);
                    potoms[p[b]][b].push_back(i);
                    b = p[b];
                }
            }
        }
    }
    printf("%d\n%d %d", ans, a1 + 1, a2 + 1);
    return 0;
}