#include<bits/stdc++.h>

using namespace std;

int timer;
vector<pair<int, int>> tins;
vector<int> h;
int st2;
vector<vector<int>> graph;
vector <pair<int, int>> m;
vector<int> firstin;
vector<int> tout;
void dfs(int i, int glub)
{
    h[i] = glub;
    firstin[i] = timer;
    timer++;
    tins.push_back(make_pair(h[i], i));
    for (int j = 0; j < graph[i].size(); j++)
    {
        dfs(graph[i][j], glub + 1);
        timer++;
        tins.push_back(make_pair(h[i], i));
    }
    tout[i] = timer;
}
pair<int, int> minotr(int i, int j)
{
    //cout << i << " " << j << endl;
    if (i == j)
    {
        return m[i];
    }
    if (i % 2 != 0)
    {
        return min(minotr(i + 1, j), m[i]);
    }
    if (j % 2 == 0)
    {
        return min(m[j], minotr(i, j - 1));
    }
    return minotr(i / 2, j / 2);
}
int lca(int i, int j)
{
    return minotr(min(firstin[i], firstin[j]) + st2, max(firstin[i], firstin[j]) + st2).second;
}
int rasst(int i, int j)
{
    return h[i] + h[j] - 2 * h[lca(i, j)];
}
int log_2(int a)
{
    //cout << a;
    int i = 1;
    int ret = 0;
    while (i < a)
    {
        i *= 2;
        ret++;
    }
    return i;
}
bool is_father(int i, int j)
{
    if (firstin[i] <= firstin[j] && tout[i] >= tout[j])
    {
        return true;
    }
    return false;
}
int main()
{
    int n;
    cin >> n;
    firstin.resize(n);
    graph.resize(n);
    tout.resize(n);
    int k;
    cin >> k;
    for (int i = 0; i < n - 1; i++)
    {
        int tmp;
        cin >> tmp;
        graph[tmp - 1].push_back(i + 1);
    }
    h.resize(n);
    timer = 0;
    dfs(0, 0);
    st2 = log_2((int)tins.size());
    //st2 = 1;
    //for (int i = 0; i < log2; i++)
   // {
   //     st2 *= 2;
   // }
    m.resize(st2 * 2);
    for (int i = st2; i < st2 + tins.size(); i++)
    {
        m[i] = tins[i - st2];
    }
    for (int i = st2 - 1; i > 0; i--)
    {
        m[i] = min(m[2 * i], m[2 * i + 1]);
    }
    vector<pair<int, int>> par(k);
    for (int i = 0; i < k; i++)
    {
        cin >> par[i].first >> par[i].second;
        par[i].first--;
        par[i].second--;
        //cout << par[i].first << " " << par[i].second << endl;
    }
    int maxper = 0;
    int a1, a2;
    a1 = 1;
    a2 = 2;
    //cout << st2 << endl;
    for (int i = 0; i < k; i++)
    {
        for (int j = 0; j < k; j++)
        {
            if (i == j)
            {
                continue;
            }
            if (lca(par[i].first, par[i].second) == lca(par[j].first, par[j].second))
            {
                if (rasst(lca(par[i].first, par[j].first), lca(par[i].second, par[j].second)) > maxper)
                {
                    //cout << i << " " << j << endl;
                    //cout << rasst(lca(par[i].first, par[j].first), lca(par[i].second, par[j].second)) << endl;
                    maxper = rasst(lca(par[i].first, par[j].first), lca(par[i].second, par[j].second));
                    a1 = i + 1;
                    a2 = j + 1;
                }
                else if (rasst(lca(par[i].first, par[j].second), lca(par[i].second, par[j].first)) > maxper)
                {
                    maxper = rasst(lca(par[i].first, par[j].second), lca(par[i].second, par[j].first));
                    a1 = i + 1;
                    a2 = j + 1;
                }
            }
            else if (is_father(lca(par[i].first, par[i].second), lca(par[j].first, par[j].second)))
            {
                int tmpp = lca(par[j].first, par[j].second);
                if (is_father(tmpp, par[i].first))
                {
                    if (maxper < rasst(lca(par[i].first, par[j].first), tmpp) || maxper < rasst(lca(par[i].first, par[j].second), tmpp))
                    {
                        maxper = max(rasst(lca(par[i].first, par[j].first), tmpp), rasst(lca(par[i].first, par[j].second), tmpp));
                        a1 = i + 1;
                        a2 = j + 1;
                    }
                }
                else if (is_father(tmpp, par[i].second))
                {
                    if (maxper < rasst(lca(par[i].second, par[j].first), tmpp) || maxper < rasst(lca(par[i].second, par[j].second), tmpp))
                    {
                        maxper = max(rasst(lca(par[i].second, par[j].first), tmpp), rasst(lca(par[i].second, par[j].second), tmpp));
                        a1 = i + 1;
                        a2 = j + 1;
                    }
                }
            }
            else if (is_father(lca(par[j].first, par[j].second), lca(par[i].first, par[i].second)))
            {
                int tmpp = lca(par[i].first, par[i].second);
                if (is_father(tmpp, par[j].first))
                {
                    if (maxper < rasst(lca(par[j].first, par[i].first), tmpp) || maxper < rasst(lca(par[j].first, par[i].second), tmpp))
                    {
                        maxper = max(rasst(lca(par[j].first, par[i].first), tmpp), rasst(lca(par[j].first, par[i].second), tmpp));
                        a1 = i + 1;
                        a2 = j + 1;
                    }
                }
                else if (is_father(tmpp, par[j].second))
                {
                    if (maxper < rasst(lca(par[j].first, par[i].first), tmpp) || maxper < rasst(lca(par[j].first, par[i].second), tmpp))
                    {
                        maxper = max(rasst(lca(par[j].second, par[i].first), tmpp), rasst(lca(par[j].second, par[i].second), tmpp));
                        a1 = i + 1;
                        a2 = j + 1;
                    }
                }
            }
        }
        //cout << "A" << endl;
    }
    cout << maxper << endl;
    cout << a1 << " " << a2;
}
