#include <bits/stdc++.h>
#define pii pair<int, int>
#define F first
#define S second;

using namespace std;

int a[200001];
int b[200001];
int ln[200001];
int p[200001];
int lt[200001];
int rt[200001];
vector<int> edge[200001];
vector<pii> sp[21];
vector<int> st;
vector<int> eul;
vector<int> lvl;

void dfs(int u, int lv){
    lt[u] = eul.size();
    eul.push_back(u);
    lvl.push_back(lv);
    for (auto v: edge[u]){
        dfs(v, lv + 1);
        eul.push_back(u);
        lvl.push_back(lv);
    }
    rt[u] = eul.size() - 1;
}

void build(){
    sp[0].resize(eul.size());
    st.resize(eul.size() + 1);
    st[0] = -1;
    for (int i = 0; i < sp[0].size(); i++){
        st[i + 1] = st[(i + 1) / 2] + 1;
        sp[0][i] = pii(lvl[i], i);
    }
    for (int j = 1; j < 20; j++){
        sp[j].resize(eul.size());
        for (int i = 0; i + (1 << j) <= sp[0].size(); i++){
            sp[j][i] = min(sp[j - 1][i], sp[j - 1][i + (1 << (j - 1))]);
        }
    }
}

pii minx(int l, int r){
    int j = st[r - l];
    return min(sp[j][l], sp[j][r - (1 << j)]);
}

int getd(int a, int b){
    if (rt[a] > lt[b])
        swap(a, b);
    pii p = minx(lt[a], rt[b] + 1);
    return lvl[lt[a]] + lvl[rt[b]] - 2 * p.F;
}

int main(){
    #ifndef DEBUG
    freopen("twopaths.in", "r", stdin);
    freopen("twopaths.out", "w", stdout);
    #else
    freopen("input.txt", "r", stdin);
    #endif // DEBUG
    int n, k;
    cin >> n >> k;
    for (int i = 1; i < n; i++){
        cin >> p[i];
        p[i]--;
        edge[p[i]].push_back(i);
    }
    dfs(0, 0);
    build();
    for (int i = 0; i < k; i++){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        ln[i] = getd(a[i], b[i]);
    }
    int mx = -1;
    int mxi = -1, mxj = -1;
    for (int i = 0; i < k; i++){
        for (int j = i + 1; j < k; j++){
            int ln1 = ln[i] + ln[j] - min(getd(a[i], b[j]) + getd(a[j], b[i]), getd(a[i], a[j]) + getd(b[j], b[i]));
            if (ln1 < 0) ln1 = 0;
            ln1 /= 2;
            if (ln1 > mx){
                mx = ln1;
                mxi = i + 1;
                mxj = j + 1;
            }
        }
    }
    cout << mx << "\n" << mxi << " " << mxj;
    return 0;
}
