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

vector<vector<int>> g;
vector<int> path_to;
vector<int> order;
vector<int> first;

struct ST {
    vector<pair<int,int>> v;
    void init(int n) {
        v.resize(n);
    }
    void set(int i, pair<int,int> p) {
        v[i] = p;
    }
    pair<int,int> min(int l, int r) {
        pair<int,int> a = {INT_MAX, INT_MAX};
        for(int i = l; i <= r; ++i) {
            if(v[i].first < a.first) {
                a = v[i];
            }
        }
        return a;
    }
};

inline void dfs(int v, int path) {
    path_to[v] = path;
    first[v] = order.size();
    order.push_back(v);
    for(int w : g[v]) {
        dfs(w, path+1);
        order.push_back(v);
    }
}

ST st;

void init_st() {
    int sz = order.size();
    st.init(sz);
    for(int i = 0; i < sz; ++i) {
        st.set(i, {path_to[order[i]], order[i]});
    }
}

inline bool is_master(int m, int s) {
    return order[m] <= order[s];
}

struct IC {
    int master;
    int slave;
    IC(int master, int slave) : master(master), slave(slave) {
        assert(is_master(master, slave));
    }
};

inline IC make_ic(int a, int b) {
    return is_master(a, b) ? IC(a, b) : IC(b, a);
}

inline int lcs(int a, int b) {
    int l = first[a], r = first[b];
    if(l > r) swap(l, r);
    return st.min(l, r).second;
}

inline int common_path_ic(IC a, IC b) {
    int cm = lcs(a.slave, b.slave);
    if(is_master(cm, a.master) || is_master(cm, b.master)) {
        return 0;
    }
    int ans = path_to[cm] - max(path_to[a.master], path_to[b.master]);
    assert(ans >= 0);
    return ans;
}

struct C {
    int a, b, cm;
    IC one, two;
    C(int a, int b) : a(a), b(b), cm(lcs(a, b)), one(cm, a), two(cm, b) {
    }
};

inline int common_path(C a, C b) {
    return common_path_ic(a.one, b.one) + common_path_ic(a.one, b.two) + common_path_ic(a.two, b.one) + common_path_ic(a.two, b.two);
}

int main() {
    #define FNAME "twopaths"
    #ifndef LOCAL
    freopen(FNAME ".in", "r", stdin);
    freopen(FNAME ".out", "w", stdout);
    #endif
    int n, k;
    scanf("%d%d", &n, &k);
    g.resize(n);
    path_to.resize(n);
    first.resize(n);
    for(int i = 1; i < n; ++i) {
        int m;
        scanf("%d", &m);
        --m;
        g[m].push_back(i);
    }
    dfs(0, 0);
    init_st();
    vector<C> c;
    for(int i = 0; i < k; ++i) {
        int a, b;
        scanf("%d%d", &a, &b);
        --a, --b;
        c.push_back(C(a, b));
    }
    pair<int,int> ans_p = {-1, -1};
    int best_ans = -1;
    for(int i = 0; i < k; ++i) {
        for(int j = i+1; j < k; ++j) {
            int a = common_path(c[i], c[j]);
            if(a > best_ans) {
                best_ans = a;
                ans_p = {i, j};
            }
        }
    }
    printf("%d\n%d %d\n", best_ans, ans_p.first+1, ans_p.second+1);
    return 0;
}
