#include <bits/stdc++.h>

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

ll n, k;
ll p[123456];
ll h[123456];
ll a[123456];
ll b[123456];
vector<ll> predk[123456];
map<ll, vector<ll>> potoms[123456];
ll cntnow[56789];
ll tin[123456];
ll tout[123456];
ll nowtime = 0;
bool GAGAGA = true;

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

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
    cin >> n >> k;
    for (int i = 1; i < n; i++)
    {
        ll val;
        cin >> val;
        p[i] = val - 1;
        potoms[val - 1][i] = vector<ll>();
    }
    dfs0(0, 0);
    ll ans = 0;
    ll a11=0, a22=1;
    for (int i = 0; i < k; i++)
    {
        cin >> a[i] >> b[i];
        if ((tin[a[i]] < tin[b[i]] && tout[a[i]] > tout[b[i]]) || (tin[b[i]] < tin[a[i]] && tout[b[i]] > tout[a[i]]))
        {
            continue;
        }
        else
        {
            GAGAGA = true;
        }
    }
    if (!GAGAGA)
    {
        cout << "1\n2 1";
        return 0;
    }
    for (int i = 0; i < k; i++)
    {
        ll a2 = a[i], b2 = b[i];
        ll aa = a2;
        ll bb = b2;
        aa--;
        bb--;
        memset(cntnow, 0, sizeof(cntnow));
        a2--;
        b2--;
        ll cnt = 0;
        while (a2 != b2)
        {
            cnt++;
            if (h[a2] >= h[b2])
            {
                //predk[a2].push_b2a2ck(i);
                //potoms[p[a2]][a2].push_b2a2ck(i);
                a2 = p[a2];
            }
            else
            {
                //predk[b2].push_b2a2ck(i);
                //potoms[p[b2]][b2].push_b2a2ck(i);
                b2 = p[b2];
            }
        }
        if (cnt > ans)
        {
            a2 = aa;
            b2 = bb;
            while (a2 != b2)
            {
                if (h[a2] >= h[b2])
                {
                    for (auto j : predk[a2])
                    {
                        cntnow[j]++;
                        if (cntnow[j] > ans)
                        {
                            ans = cntnow[j];
                            a11 = j;
                            a22 = i;
                        }
                    }
                    predk[a2].push_back(i);
                    potoms[p[a2]][a2].push_back(i);
                    a2 = p[a2];
                }
                else
                {
                    for (auto j : predk[b2])
                    {
                        cntnow[j]++;
                        if (cntnow[j] > ans)
                        {
                            ans = cntnow[j];
                            a11 = j;
                            a22 = i;
                        }
                    }
                    predk[b2].push_back(i);
                    potoms[p[b2]][b2].push_back(i);
                    b2 = p[b2];
                }
            }
        }
        else
        {
            a2 = aa;
            b2 = bb;
            while (a2 != b2)
            {
                cnt++;
                if (h[a2] >= h[b2])
                {
                    predk[a2].push_back(i);
                    potoms[p[a2]][a2].push_back(i);
                    a2 = p[a2];
                }
                else
                {
                    predk[b2].push_back(i);
                    potoms[p[b2]][b2].push_back(i);
                    b2 = p[b2];
                }
            }
        }
    }
    cout << ans << endl;
    cout << a11 + 1 << " " << a22 + 1 << endl;
    return 0;
}