#include <iostream>
#include <vector>
#include <cstdio>

using namespace std;

void dfs(const vector<vector<int>> &children, int v, vector<pair<int, int>> &visits, vector<int> &depth, vector<int> &t_in, vector<int> &t_out) {
    static int dfs_time = 0;
    t_in[v] = dfs_time++;
    visits.push_back(make_pair(depth[v], v));
    for (int u : children[v]) {
        depth[u] = depth[v] + 1;
        dfs(children, u, visits, depth, t_in, t_out);
        visits.push_back(make_pair(depth[v], v));
    }
    t_out[v] = dfs_time++;
}

vector<int> log2;

void init_log2(int n) {
    log2.assign(n + 1, 0);
    for (int i = 0; (1 << i) <= n; i++) {
        log2[(1 << i)] = i;
    }
    for (int i = 3; i <= n; i++) {
        if (!log2[i]) {
            log2[i] = log2[i - 1];
        }
    }
}

template <class T>
vector<vector<T>> make_sparse(const vector<T> &arr) {
    int n = arr.size();
    vector<vector<T>> sparse(log2[n] + 1);
    sparse[0] = arr;
    for (int i = 1; (1 << i) <= n; i++) {
        int width = (1 << i);
        sparse[i].resize(n - width + 1);
        for (int j = 0; j < (int)sparse[i].size(); j++) {
            sparse[i][j] = min(sparse[i - 1][j], sparse[i - 1][j + width / 2]);
        }
    }
    return sparse;
}

template <class T>
T min_on_range(const vector<vector<T>> &sparse, int i, int j) {
    int width = j - i + 1;
    return min(sparse[log2[width]][i], sparse[log2[width]][j - width + 1]);
}

int lca(const vector<vector<pair<int, int>>> &sparse, const vector<int> &t_in, int i, int j) {
    int t1 = t_in[i];
    int t2 = t_in[j];
    if (t2 < t1) {
        swap(t1, t2);
    }
    return min_on_range(sparse, t1, t2).second;
}

bool is_ancestor(const vector<int> &t_in, const vector<int> &t_out, int a, int b) {
    return t_in[a] <= t_in[b] && t_out[b] <= t_out[a];
}

bool is_between(const vector<int> &t_in, const vector<int> &t_out, int a, int b, int c) {
    return is_ancestor(t_in, t_out, a, b) && is_ancestor(t_in, t_out, b, c);
}

int main() {
#ifndef LOCAL
    freopen("twopaths.in", "r", stdin);
    freopen("twopaths.out", "w", stdout);
#endif
    int n, k;
    cin >> n >> k;
    vector<int> tree(n);
    vector<vector<int>> children(n);
    vector<int> depth(n, 0);
    for (int i = 1; i < n; i++) {
        int p;
        cin >> p;
        p--;
        tree[i] = p;
        children[p].push_back(i);
    }
    vector<pair<int, int>> visits;
    visits.reserve(2 * n);
    vector<int> t_in(n), t_out(n);
    dfs(children, 0, visits, depth, t_in, t_out);

    init_log2(2 * n);
    vector<vector<pair<int, int>>> sparse = make_sparse(visits);
    vector<pair<int, int>> paths(k);
    for (int i = 0; i < k; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        if (b < a) {
            swap(a, b);
        }
        paths[i] = make_pair(a, b);
    }

    int max_len = 0, first_path = 0, second_path = 1;
    for (int i = 0; i < k; i++) {
        int ai = paths[i].first;
        int bi = paths[i].second;
        int li = lca(sparse, t_in, ai, bi);
        for (int j = i + 1; j < k; j++) {
            int aj = paths[j].first;
            int bj = paths[j].second;
            int lj = lca(sparse, t_in, aj, bj);
            int l1 = lca(sparse, t_in, ai, aj);
            int l2 = lca(sparse, t_in, bi, bj);
            int len;
            if (li == lj) {
                len = depth[l1] + depth[l2] - 2 * depth[li];
            } else if (is_between(t_in, t_out, li, lj, ai)) {
                len = depth[l1] - depth[lj];
            } else if (is_between(t_in, t_out, li, lj, bi)) {
                len = depth[l2] - depth[lj];
            } else if (is_between(t_in, t_out, lj, li, aj)) {
                len = depth[l1] - depth[li];
            } else if (is_between(t_in, t_out, lj, li, bj)) {
                len = depth[l2] - depth[li];
            } else {
                len = 0;
            }
            if (len > max_len) {
                max_len = len;
                first_path = i;
                second_path = j;
            }
        }
    }

    cout << max_len << endl;
    cout << (first_path + 1) << ' ' << (second_path + 1) << endl;

    return 0;
}
