#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define all(v) v.begin(), v.end()

vector<int> g[200007];
int tin[200007], tout[200007], f[200007];
int h[200007];
pair<int, int> zap[200007];
int dva[30];
vector<int> eul, st;
vector<int> spars[30];
int tc = 2;

void dfs(int v, int deep, int p){
    h[v] = deep;
    tin[v] = tc++;
    eul.push_back(v);
    f[v] = eul.size() - 1;
    for (auto u:g[v]){
        dfs(u, deep + 1, v);
        eul.push_back(v);
    }
    tout[v] = tc++;
}

bool ispar(int v, int u){
    if (tin[v] <= tin[u] && tout[u] <= tout[v]){
        return 1;
    }
    return 0;
}

void make_spars(){
    int n = eul.size();
    dva[0] = 1;
    for (int i = 1; i < 30; i++){
        dva[i] = 2 * dva[i - 1];
    }
    st.resize(n);
    st[1] = 0;
    for (int i = 2; i < n; i++){
        st[i] = st[i / 2] + 1;
    }
    spars[0].resize(n);
    for (int i = 0; i < n; i++){
        spars[0][i] = eul[i];
    }
    for (int i = 1; i < 30; i++){
        int len = dva[i - 1];
        spars[i].resize(n);
        for (int j = 0; j + len < n; j++){
            if (h[spars[i - 1][j]] < h[spars[i - 1][j + len]]){
                spars[i][j] = spars[i - 1][j];
            } else {
                spars[i][j] = spars[i - 1][j + len];
            }
        }
    }
}

int getmin(int l, int r){
    int q = st[r - l + 1];
    int len = dva[q];
    if (h[spars[q][l]] < h[spars[q][r - len + 1]]){
        return spars[q][l];
    } else {
        return spars[q][r - len + 1];
    }
}

int getlca(int u, int v){
    int l = min(f[u], f[v]);
    int r = max(f[u], f[v]);
    return getmin(l, r);
}



int compart(int ii, int jj){
    int a = zap[ii].first;
    int b = zap[ii].second;
    int aa = zap[jj].first;
    int bb = zap[jj].second;
    int c = getlca(a, b);
    int cc = getlca(aa, bb);
    //cout << a + 1 << " " << c + 1 << " " << b + 1 << endl;
    if ((!ispar(cc, c)) && (!ispar(c, cc))){
        return 0;
    }
    int ans = 0;
    if (!ispar(c, cc)){
        swap(a, aa);
        swap(b, bb);
        swap(c, cc);
    }
    ans += max(-h[cc] + h[getlca(aa, a)], 0);
    ans += max(-h[cc] + h[getlca(aa, b)], 0);
    ans += max(-h[cc] + h[getlca(bb, a)], 0);
    ans += max(-h[cc] + h[getlca(bb, b)], 0);
    return ans;
}

int main(){
    //freopen("input.txt", "r", stdin);
    freopen("twopaths.in", "r", stdin);
    freopen("twopaths.out", "w", stdout);
    int n, k;
    scanf("%d %d\n", &n, &k);
    for (int i = 1; i < n; i++){
        int x;
        scanf("%d ", &x);
        x--;
        g[x].push_back(i);
    }
    dfs(0, 0, 0);
    make_spars();
    for (int i = 0; i < k; i++){
        scanf("%d %d", &zap[i].first, &zap[i].second);
        zap[i].first--;
        zap[i].second--;
    }
    int com = -1, l = -1, r = -1;
    for (int i = 0; i < k; i++){
        for (int j = i + 1; j < k; j++){
            int t = compart(i, j);
            if (t > com){
                com = t;
                l = i + 1;
                r = j + 1;
            }
        }
    }
    printf("%d\n%d %d", com, l, r);
    return 0;
}


