#include <bits/stdc++.h>
#define pb push_back
using namespace std;
int n, k;
vector <int> v[200000];
int tin[200000];
int tout[200000];
int t = 0;
int dp[20][200000];
int p[200000];
int q[200000];
int a[200000];
int b[200000];
int h[200000];
void dfs(int i, int d) {
    tin[i] = t;
    t++;
    h[i] = d;
    for (int j = 0; j < v[i].size(); j++) {
        dfs(v[i][j], d + 1);
    }
    tout[i] = t;
}
bool upper(int u, int v) {
    if (tin[u] <= tin[v] && tout[v] <= tout[u]) return true;
    return false;
}
int lca(int u, int v) {
    if (upper(u, v)) return u;
    if (upper(v, u)) return v;
    for (int j = 19; j >= 0; j--) {
        if (!upper(dp[j][u], v)) u = dp[j][u];
    }
    u = p[u];
    return u;
}
int main() {
    freopen("twopaths.in", "r", stdin);
    freopen("twopaths.out", "w", stdout);
    scanf("%d %d", &n, &k);
    p[0] = 0;
    for (int i = 1; i < n; i++) {
        int x;
        scanf("%d", &x);
        p[i] = x;
        p[i]--;
        v[p[i]].pb(i);
    }
    dfs(0, 0);
    for (int i = 0; i < n; i++) dp[0][i] = p[i];
    for (int j = 1; j < 20; j++) {
            for (int i = 0; i < n; i++) dp[j][i] = dp[j - 1][dp[j - 1][i]];
    }
    for (int i = 0; i < k; i++) {
        int x, y;
        scanf("%d %d", &x, &y);
        a[i] = x;
        b[i] = y;
        a[i]--;
        b[i]--;
        q[i] = lca(a[i], b[i]);
    }
    int ind1 = 0;
    int ind2 = 1;
    int mx = 0;
    for (int i = 0; i < k; i++) {
        for (int j = i + 1; j < k; j++) {
            int cur = 0;
            int x = lca(a[i], a[j]);
            int y = lca(a[i], b[j]);
            int z = lca(b[i], a[j]);
            int t = lca(b[i], b[j]);
            if (upper(q[i], q[j])) {
                if (upper(q[j], a[i]) && (x != q[j] || y != q[j])) {
                    cur += h[a[i]] - h[q[j]];
                    if (x != q[j]) cur += h[x] - h[a[i]];
                    if (y != q[j]) cur += h[y] - h[a[i]];
                }
                if (upper(q[j], b[i]) && (z != q[j] || t != q[j])) {
                    cur += h[b[i]] - h[q[j]];
                    if (z != q[j]) cur += h[z] - h[b[i]];
                    if (t != q[j]) cur += h[t] - h[b[i]];
                }
            }
            else if (upper(q[j], q[i])) {
                if (upper(q[i], a[j]) && (x != q[i] || z != q[i])) {
                    cur += h[a[j]] - h[q[i]];
                    if (x != q[i]) cur += h[x] - h[a[j]];
                    if (z != q[i]) cur += h[z] - h[a[j]];
                }
                if (upper(q[i], b[j]) && (y != q[i] || t != q[i])) {
                    cur += h[b[j]] - h[q[i]];
                    if (y != q[i]) cur += h[y] - h[b[j]];
                    if (t != q[i]) cur += h[t] - h[b[j]];
                }
            }
            if (cur > mx) {
                ind1 = i;
                ind2 = j;
                mx = cur;
            }
        }
    }
    printf("%d\n", mx);
    printf("%d %d\n", ind1 + 1, ind2 + 1);
}
