#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>

using namespace std;

int n, t, k;
int par[1000000];
int tin[1000000];
int tout[1000000];
int ln[1000000];
int rn[1000000];
vector < vector <int> > child(1000000);
vector <int> euler;
int h[1000000];
pair <int, int> kr[1000000];
vector < vector <int> > cc(1000000);
int st[400001][40];
unordered_map <int, int> ch;
set < pair <int, int> > tt;
set < pair <int, int> > pp;
map < pair <int, int>, int > fnd1;
map < pair <int, int>, int > fnd2;

void build()
{
    for (int i = 0; i < euler.size(); i++)
    {
        st[i][0] = i;
    }

    for (int len = 1; (1 << len) <= euler.size(); len++)
    {
        for (int i = 0; i + (1 << len) - 1 < euler.size(); i++)
        {
            int p1 = st[i][len - 1];
            int g = i + (1 << (len - 1));
            int p2 = st[g][len - 1];
            if (h[euler[p1]] < h[euler[p2]])
            {
                st[i][len] = p1;
            } else
            {
                st[i][len] = p2;
            }
        }
    }
}

int get(int l, int r)
{
    if (r == l)
    {
        return l;
    }

    int len = log(r - l) / log(2);

    int p1 = st[l][len];
    int p2 = st[r - (1 << len) + 1][len];
    if (h[euler[p1]] < h[euler[p2]])
    {
        return p1;
    } else
    {
        return p2;
    }
}


void dfs(int v, int h1)
{
    h[v] = h1;
    tin[v] = t;
    t++;
    ln[v] = euler.size();
    euler.push_back(v);

    for (int g = 0; g < child[v].size(); g++)
    {
        int to = child[v][g];
        if (to != par[v])
        {
            euler.push_back(v);
            dfs(to, h1 + 1);
        }
    }

    rn[v] = int(euler.size()) - 1;

    tout[v] = t;
    t++;
}

int lca(int a, int b)
{
    int l1 = ln[a];
    int r1 = ln[b];
    if (l1 > r1)
    {
        swap(l1, r1);
    }

    int p = get(l1, r1);
    return euler[p];
}

int cl(int a, int b, int c, int d)
{
    if (tin[b] > tin[a])
    {
        swap(a, b);
    }

    if (tin[d] > tin[c])
    {
        swap(c, d);
    }

    int p = lca(a, c);
    if (h[p] > h[b] && h[p] > h[d])
    {
        return min(-h[b] + h[p], -h[d] + h[p]);
    }

    return 0;
}

bool pr(int a, int b)
{
    if (tin[a] < tin[b])
    {
        swap(a, b);
    }

    return (tin[b] < tin[a] && tout[b] > tout[a]);
}

int main()
{
    ios_base::sync_with_stdio(false);
    freopen("twopaths.in", "r", stdin);
    freopen("twopaths.out", "w", stdout);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> n >> k;
    t = 1;
    for (int i = 2; i <= n; i++)
    {
        int pp;
        cin >> pp;
        par[i] = pp;
        child[pp].push_back(i);
    }

    dfs(1, 1);

    build();

    for (int i = 1; i <= k; i++)
    {
        cin >> kr[i].first >> kr[i].second;
    }

    if (k > 1000)
    {
        int ans = -1;
        int i1 = 0;
        int g1 = 0;

        for (int i = 1; i <= k; i++)
        {
            int a = kr[i].first;
            int b = kr[i].second;

            if (a > b)
            {
                swap(a, b);
            }

            if (tt.find({a, b}) != tt.end())
            {
                pp.insert({a, b});
                fnd2[{a, b}] = i;
                continue;
            }

            fnd1[{a, b}] = i;
            tt.insert({a, b});

            int p = lca(a, b);

            int g = a;
            while (g != p)
            {
                cc[g].push_back(i);
                g = par[g];
            }

            g = b;
            while (g != p)
            {
                cc[g].push_back(i);
                g = par[g];
            }
        }

        for (auto it = pp.begin(); it != pp.end(); it++)
        {
            int a = (it -> first);
            int b = (it -> second);
            int p = lca(a, b);

            int calc = 0;

            int g = a;
            while (g != p)
            {
                calc++;
                g = par[g];
            }

            g = b;
            while (g != p)
            {
                calc++;
                g = par[g];
            }

            if (calc > ans)
            {
                ans = calc;
                i1 = fnd1[{a, b}];
                g1 = fnd2[{a, b}];
            }
        }

        for (int i = 1; i <= k; i++)
        {
            int a = kr[i].first;
            int b = kr[i].second;
            int p = lca(a, b);

            int calc = -1;
            int g2 = 0;

            ch.clear();
            int g = a;
            while (g != p)
            {
                for (int j = 0; j < cc[g].size(); j++)
                {
                    ch[cc[g][j]]++;
                    if (ch[cc[g][j]] > calc)
                    {
                        calc = ch[cc[g][j]];
                        g2 = cc[g][j];
                    }
                }

                g = par[g];
            }

            g = b;
            while (g != p)
            {
                for (int j = 0; j < cc[g].size(); j++)
                {
                    ch[cc[g][j]]++;
                    if (ch[cc[g][j]] > calc)
                    {
                        calc = ch[cc[g][j]];
                        g2 = cc[g][j];
                    }
                }

                g = par[g];
            }

            if (calc > ans)
            {
                ans = calc;
                i1 = i;
                g1 = g2;
            }
        }

        cout << ans << endl << i1 << " " << g1 << endl;
        return 0;
    }

    int ans = -1;
    int i1 = 0;
    int g1 = 0;
    for (int i = 1; i <= k; i++)
    {
        for (int g = i + 1; g <= k; g++)
        {
            int a = kr[i].first;
            int b = kr[i].second;
            int c = kr[g].first;
            int d = kr[g].second;

            if (tin[a] < tin[b])
            {
                swap(a, b);
            }

            if (tin[c] < tin[d])
            {
                swap(c, d);
            }

            int e = lca(a, b);
            int f = lca(c, d);

            int calc = cl(a, e, c, f);

            if (!pr(a, b) && !pr(c, d))
            {
                calc += cl(a, e, f, d) + cl(e, b, f, d) + cl(e, b, c, f);
            } else
            if (!pr(a, b))
            {
                calc += cl(e, b, c, f);
            } else
            if (!pr(c, d))
            {
                calc += cl(a, e, f, d);
            }

            if (calc > ans)
            {
                ans = calc;
                i1 = i;
                g1 = g;
            }
        }
    }

    cout << ans << endl << i1 << " " << g1 << endl;
    return 0;
}
