#include <bits/stdc++.h>

using namespace std;

const int MX = 1e+5 + 42;

vector<int> gr[MX];
vector<pair<int, int>> guysribs[5001];
map<pair<int, int>, vector<int>> ribsguys;

inline void init(vector<int> &path, int number) {
    for (int i = 0; i < path.size() - 1; ++i) {
        pair<int, int> p = {path[i], path[i + 1]};
        if (p.first > p.second) swap(p.first, p.second);
        guysribs[number].push_back(p);
        ribsguys[p].push_back(number);
    }
}

inline void dfs(int start, int finish, int number, vector<int> &path, int p = -1) {
    if (start == finish) {
        init(path, number);
        return;
    }
    for (auto u : gr[start]) {
        if (u != p) {
            path.push_back(u);
            dfs(u, finish, number, path, start);
            path.pop_back();
        }
    }
}

int main() {
    freopen("twopaths.in", "r", stdin);
    freopen("twopaths.out", "w", stdout);

    int n, k;
    cin >> n >> k;
    for (int i = 2; i <= n; ++i) {
        int t;
        cin >> t;
        gr[t].push_back(i);
        gr[i].push_back(t); /// no prior!!
    }
    vector<pair<int, int>> runners;
    for (int i = 0; i < k; ++i) {
        int a, b;
        cin >> a >> b;
        if (a > b) swap(a, b);
        runners.push_back({a, b});
    }

    for (int i = 0; i < k; ++i) {
        vector<int> trash = {runners[i].first};
        dfs(runners[i].first, runners[i].second, i, trash);
    }


   /* cout << endl << endl;
    for (auto i : ribsguys) {
        cout << i.first.first << " " << i.first.second << ": " << endl;
        for (auto j : i.second) cout << j + 1 << " ";
        cout << endl;
    }
    cout << endl << endl;*/

    int res = 0;
    pair<int, int> pres = {0, 0};
    for (int i = 0; i < k; ++i) {
        vector<int> local(k + 1);
        for (auto j : guysribs[i]) {
            for (auto p : ribsguys[j]) {
                ++local[p];
            }
        }

        int lmax = 0;
        pair<int, int> pmax;
        for (int ii = 0; ii < k; ++ii) {
            if (i != ii and local[ii] > lmax) {
                lmax = local[ii];
                pmax = {i, ii};
            }
        }
        if (lmax > res) {
            res = lmax;
            pres = pmax;
        }
        if (clock() / (double)CLOCKS_PER_SEC >= 1.97) break;

    }

    cout << res << endl;
    cout << pres.first + 1 << " " << pres.second + 1 << endl;

}
