#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

#define INF 1791791791;

class sparse_table
{
    vector<int> log_table;
    vector<vector<int> > st;
    vector<int> a;
  public:
    sparse_table() {}
    sparse_table(vector<int> _a)
    {
        a = _a;
        int n = _a.size();
        log_table.resize(n + 1, 0);
        for (int i = 2; i <= n; i++)
            log_table[i] = log_table[i / 2] + 1;
        st.resize(log_table[n] + 1, vector<int>(n, 0));
        for (int i = 0; i < n; i++)
            st[0][i] = i;
        for (int k = 1; k <= log_table[n]; k++)
        {
            for (int j = 0; j + (1 << (k - 1)) < n; j++)
            {
                if (a[st[k - 1][j]] < a[st[k - 1][j + (1 << (k - 1))]])
                    st[k][j] = st[k - 1][j];
                else
                    st[k][j] = st[k - 1][j + (1 << (k - 1))];
            }
        }
    }
    int get_min(int i, int j)
    {
        if (a[st[log_table[j - i + 1]][i]] < a[st[log_table[j - i + 1]][j - (1 << log_table[j - i + 1]) + 1]])
            return st[log_table[j - i + 1]][i];
        else
            return st[log_table[j - i + 1]][j - (1 << log_table[j - i + 1]) + 1];
    }
};

int n;
vector<int>* tree;
vector<int> vec;
vector<int> hv;
int* first;
int* h;
int* tin, *tout;
int _time = 0;

void dfs(int u, int hg, int par)
{
    h[u] = hg;
    tin[u] = _time++;
    vec.push_back(u);
    first[u] = hv.size();
    hv.push_back(h[u]);
    for (int v : tree[u])
    {
        //vec.push_back(u);
        //hv.push_back(h[u]);
        dfs(v, hg + 1, u);
        vec.push_back(u);
        hv.push_back(h[u]);
    }
    tout[u] = _time++;
    //vec.push_back(u);
    //hv.push_back(h[u]);
}

sparse_table st;

int lca(int u, int v)
{
    if (first[u] > first[v])
        swap(u, v);
    return vec[st.get_min(first[u], first[v])];
}

bool is_par(int u, int v)
{
    return tin[u] <= tin[v] && tout[v] <= tout[u];
}

int dist(int a, int b)
{
    if (a == -1 || b == -1)
        return 0;
    return h[a] + h[b] - 2 * h[lca(a, b)];
}

int intersection(int a, int b, int c, int d)
{
    int u = lca(a, b), v = lca(c, d);
    if (!is_par(u, v) && !is_par(v, u))
        return 0;
    if (u == v)
    {
        int p1 = lca(a, c), p2 = lca(a, d), q1 = lca(b, c), q2 = lca(b, d);
        int p, q;
        if (h[p1] > h[p2])
            p = p1;
        else
            p = p2;
        if (h[q1] > h[q2])
            q = q1;
        else
            q = q2;
        return dist(p, q);
    }
    else
    {
        if (is_par(v, u))
        {
            swap(u, v);
            swap(a, c);
            swap(b, d);
        }
        if (!is_par(v, a) && !is_par(v, b))
            return 0;
        if (!is_par(v, a))
            swap(a, b);
        int p1 = lca(a, c);
        int p2 = lca(a, d);
        if (p1 == v)
            return dist(p2, v);
        else
            return dist(p1, v);
    }
}

int main()
{
#ifndef LOCAL
    freopen("twopaths.in", "r", stdin);
    freopen("twopaths.out", "w", stdout);
#endif
    int k;
    cin >> n >> k;
    tree = new vector<int>[n];
    for (int i = 0; i < n - 1; i++)
    {
        int a;
        cin >> a;
        a--;
        tree[a].push_back(i + 1);
    }
    h = new int[n];
    tin = new int[n];
    tout = new int[n];
    first = new int[n];
    dfs(0, 0, -1);
    st = hv;
    int* u = new int[k], *v = new int[k];
    for (int i = 0; i < k; i++)
    {
        cin >> u[i] >> v[i];
        u[i]--; v[i]--;
    }
    int mx = 0, mxi = 0, mxj = 1;
    for (int i = 0; i < k; i++)
    {
        for (int j = i + 1; j < k; j++)
        {
            if (mx < intersection(u[i], v[i], u[j], v[j]))
            {
                mx = intersection(u[i], v[i], u[j], v[j]);
                mxi = i;
                mxj = j;
            }
        }
    }
    cout << mx << endl << mxi + 1 << " " << mxj + 1 << endl;
    return 0;
}
