#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int maxn = 2e5 + 10, lg = 21;

int n, m;

vector<int> e[maxn];

pair<pair<int, int>, int> p[maxn];

int l[maxn], r[maxn];

pair<int, int> q[2 * maxn][lg];

int eu[2 * maxn], sz = 0, st[maxn], h[maxn];

int findlca(int a, int b){
    int L = min(l[b], l[a]), R = max(r[a], r[b]);
    int step = st[R - L + 1];
    if (q[L][step].first < q[R - (1 << step) + 1][step].first)
        return q[L][step].second;
    return q[R - (1 << step) + 1][step].second;
}

void dfs(int v, int p){
    l[v] = sz;
    r[v] = sz;
    eu[sz] = v, sz++;
    for (int i = 0; i < e[v].size(); i++)
        if (e[v][i] != p)
            h[e[v][i]] = h[v] + 1, dfs(e[v][i], v), eu[sz] = v, r[v] = sz, sz++;
}

bool cmp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b){
    int l1 = findlca(a.first.first, a.first.second), l2 = findlca(b.first.first, b.first.second);
    return h[l1] < h[l2];
}

int dist(int a, int b){
    int lca = findlca(a, b);
    return h[a] - h[lca] + h[b] - h[lca];
}

int main()
{
    ifstream cin("twopaths.in");
    ofstream cout("twopaths.out");
    ios::sync_with_stdio(0);
    cin >> n >> m;
    st[1] = 0;
    for (int i = 2; i <= 2 * n; i++){
        st[i] = st[i - 1];
        if (st[i / 2] == st[i])
            st[i]++;
    }
    for (int i = 1; i < n; i++){
        int x;
        cin >> x;
        x--;
        e[x].push_back(i);
        e[i].push_back(x);
    }
    for (int i = 0; i < m; i++)
        cin >> p[i].first.first >> p[i].first.second, p[i].first.first--, p[i].first.second--, p[i].second = i;
    dfs(0, -1);
    for (int i = 0; i < sz; i++)
        q[i][0] = make_pair(h[eu[i]], eu[i]);
    for (int j = 1; j < lg; j++)
        for (int i = 0; i < sz; i++)
            if (q[i][j - 1].first < q[i + (1 << (j - 1))][j - 1].first)
                q[i][j] = q[i][j - 1];
            else
                q[i][j] = q[i + (1 << (j - 1))][j - 1];
    int answer = -1;
    sort(p, p + m, cmp);
    int ians, jans;
    for (int i = 0; i < m - 1; i++){
        int a = p[i].first.first, b = p[i].first.second;
        int la = findlca(a, b);
        for (int j = i + 1; j < m; j++){
            int c = p[j].first.first, d = p[j].first.second;
            int x = findlca(a, c), y = findlca(b, d);
            int lca = findlca(b, c);
            if (h[x] < h[lca])
                x = lca;
            lca = findlca(a, d);
            if (h[y] < h[lca])
                y = lca;
            if (answer < dist(x, y))
                answer = dist(x, y), ians = p[i].second + 1, jans = p[j].second + 1;
        }
    }
    cout << answer << '\n' << ians << ' ' << jans;
}
