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


using namespace std;

int n, k, p2;
vector<vector<int>> g;
vector<vector<int>> sparse;
vector<int> ti, to, d, euler, fe;
int timer = 0;

void dfs(int v) {
    ti[v] = timer++;
    fe[v] = euler.size();
    euler.push_back(v);
    for (int i : g[v]) {
        d[i] = d[v] + 1;
        dfs(i);
        euler.push_back(v);
    }
    to[v] = timer++;
}

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

int lca(int u, int v) {
    int lp2, a1, a2;
    if (u == v) {
        return u;
    }
    if (fe[u] > fe[v]) {
        swap(u, v);
    }
    for (lp2 = 0; (1 << lp2) < fe[v] - fe[u] + 1; ++lp2);
    --lp2;
    a1 = sparse[lp2][fe[u]];
    a2 = sparse[lp2][fe[v] - (1 << lp2) + 1];
    if (d[a1] < d[a2]) {
        return a1;
    } else {
        return a2;
    }
}

int comm(int u1, int v1, int u2, int v2) {
    if (!is_par(v1, v2) && !is_par(v2, v1)) {
        return 0;
    }
    int maxd = max(d[v1], d[v2]);
    int mind = d[lca(u1, u2)];
    return max(0, mind - maxd);
}

int main() {
#ifndef LOCAL
    assert(freopen("twopaths.in", "r", stdin));
    assert(freopen("twopaths.out", "w", stdout));
#endif // LOCAL
    cin >> n >> k;
    g.resize(n);
    ti.resize(n);
    to.resize(n);
    d.resize(n);
    fe.resize(n);
    int v;
    for (int i = 1; i < n; ++i) {
        cin >> v;
        --v;
        g[v].push_back(i);
    }
    dfs(0);
    for (p2 = 1; (1 << p2) <= (int) euler.size(); ++p2);
    sparse.resize(p2, vector<int>(euler.size()));
    sparse[0] = euler;
    for (int i = 1; i < p2; ++i) {
        for (int j = 0; j < (int) euler.size(); ++j) {
            if ((j + (1 << i >> 1)) < (int) euler.size()) {
                if (d[sparse[i - 1][j]] < d[sparse[i - 1][j + (1 << i >> 1)]]) {
                    sparse[i][j] = sparse[i - 1][j];
                } else {
                    sparse[i][j] = sparse[i - 1][j + (1 << i >> 1)];
                }
            }
        }
    }
    vector<pair<int, int>> c(k);
    vector<int> clca(k);
    for (int i = 0; i < k; ++i) {
        cin >> c[i].first >> c[i].second;
        --c[i].first;
        --c[i].second;
        clca[i] = lca(c[i].first, c[i].second);
        assert(comm(c[i].first, clca[i], c[i].second, clca[i]) == 0);
    }
    int ans = 0, ansi1 = 0, ansi2 = 1;
    for (int i = 0; i < k; ++i) {
        for (int j = 0; j < i; ++j) {
            int cans = comm(c[i].first,  clca[i], c[j].first,  clca[j]) +
                       comm(c[i].first,  clca[i], c[j].second, clca[j]) +
                       comm(c[i].second, clca[i], c[j].first,  clca[j]) +
                       comm(c[i].second, clca[i], c[j].second, clca[j]);
            if (cans > ans) {
                ans = cans;
                ansi1 = j;
                ansi2 = i;
            }
        }
    }
    cout << ans << '\n' << ansi1 + 1 << ' ' << ansi2 + 1 << endl;

    return 0;
}
