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


using namespace std;

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

void dfs(int v) {
    ti[v] = timer++;
    for (int i : g[v]) {
        d[i] = d[v] + 1;
        dfs(i);
    }
    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) {
    if (is_par(u, v)) {
        return u;
    }
    for (int i = p2 - 1; i >= 0; --i) {
        if (!is_par(p[i][v], u)) {
            v = p[i][v];
        }
    }
    return p[0][v];
}

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;
    for (p2 = 1; (1 << p2) <= n; ++p2);
    g.resize(n);
    p.resize(p2, vector<int>(n));
    ti.resize(n);
    to.resize(n);
    d.resize(n);
    int v;
    for (int i = 1; i < n; ++i) {
        cin >> v;
        --v;
        g[v].push_back(i);
        p[0][i] = v;
    }
    for (int i = 1; i < p2; ++i) {
        for (int j = 0; j < n; ++j) {
            p[i][j] = p[i - 1][p[i - 1][j]];
        }
    }
    dfs(0);
    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;
}
