#include <bits/stdc++.h>

#define mp make_pair
#define pb bush_back
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int N = 5e5 + 7;
const int LOG = 20;
const int M = 5e3 + 7;
const ll INF = 1e9 + 7;

int in[N], out[N], tim, nxt[N], last[N], a[N], x[N], y[N], up[N][LOG + 1], d[N], f[N];

void add(int x, int y, int v){
    nxt[v] = last[x];
    last[x] = v;
    a[v] = y;
}

void dfs(int u, int p){
    in[u] = tim++;
    if (p != -1){
        d[u] = d[p] + 1;
        up[u][0] = p;
        for (int i = 1; i < LOG; i++)
            up[u][i] = up[up[u][i - 1]][i - 1];
    }
    for (int i = last[u]; i != -1; i = nxt[i]){
        dfs(a[i], u);
    }
    out[u] = tim++;
}

int lca(int a, int b){
    //cout << a << " " << b << endl;
    if (in[a] <= in[b] && out[a] >= out[b])
        return a;
    if (in[b] <= in[a] && out[b] >= out[a])
        return b;
    for (int i = LOG; i >= 0; i--){
        int u = up[a][i];
        if (in[u] > in[b] || out[u] < out[b])
            a = u;
    }
    return up[a][0];
}

int crosses(int x, int y, int a, int b){
    int t = lca(y, b);
    if (t != y && t != b)
        return 0;
    t = y + b - t;
    if (in[x] < in[t] || in[a] < in[t] || out[x] > out[t] || out[a] > out[t])
        return 0;
    int e = lca(x, a);
    //cout << x << " " << y << " "
    //cout << x << " " << y << " " << a << " " << b << " " << t << " " << e << " " << d[e] - d[t] << endl;
    return max(0, d[e] - d[t]);
}

void init(int n, int k){
    int v = 0;
    for (int i = 0; i < n; i++)
        last[i] = -1;
    for (int i = 0; i < n - 1; i++){
        int p;
        cin >> p;
        add(p - 1, i + 1, v++);
    }
    for (int i = 0; i < k; i++){
        cin >> x[i] >> y[i];
        x[i]--, y[i]--;
        f[i] = lca(x[i], y[i]);
    }
}

int main()
{
    freopen("twopaths.in", "r", stdin);
    freopen("twopaths.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, k, q, ans = 0, an1 = 1, an2 = 2;
    cin >> n >> k;
    init(n, k);
    dfs(0, -1);
    for (int i = 0; i < k; i++){
        for (int j = i + 1; j < k; j++){
            int lca_i = f[i];
            //cout << lca_i << endl;
            int lca_j = f[j];
            //cout << lca_j << endl;
            q = crosses(x[i], lca_i, x[j], lca_j) + crosses(x[i], lca_i, y[j], lca_j) +
                crosses(y[i], lca_i, x[j], lca_j) + crosses(y[i], lca_i, y[j], lca_j);
            if (q > ans)
                ans = q, an1 = i + 1, an2 = j + 1;
        }
    }
    cout << ans << endl << an1 << " " << an2 << endl;
    return 0;
}
