#include <bits/stdc++.h>

using namespace std;

vector<vector<int> > neib;
vector<int> color;
map<pair<int, int>, int> q;
int n, k;

int dfs(int u, int f) {
    if (u == f)
        return 1;
    if (color[u])
        return 0;
    color[u] = 1;
    for (int i = 0; i < neib[u].size(); ++i) {
        if (dfs(neib[u][i], f)) {
            q[{u, neib[u][i]}]++;
            q[{neib[u][i], u}]++;
            return 1;
        }
    }
    return 0;
}

int main() {
    freopen("twopaths.in", "r", stdin);
    freopen("twopaths.out", "w", stdout);
    cin >> n >> k;
    neib.resize(n);
    color.resize(n);
    vector<pair<int, int> > p(k);
    for (int i = 1, u; i < n; ++i) {
        cin >> u;
        --u;
        neib[u].push_back(i);
        neib[i].push_back(u);
    }
    for (int i = 0, a, b; i < k; ++i) {
        cin >> a >> b;
        p[i] = {a - 1, b - 1};
    }
    int ans = 0, I = -1, J = -1;
    for (int i = 0; i < k; ++i) {
        for (int j = i + 1; j < k; ++j) {
            color.assign(n, 0);
            q.clear();
            dfs(p[i].first, p[i].second);
            color.assign(n, 0);
            dfs(p[j].first, p[j].second);
            int num = 0;
            for (auto it = q.begin(); it != q.end(); ++it)
                num += (it->second == 2);
            if (ans < num) {
                ans = num;
                I = i;
                J = j;
            }
        }
    }
    cout << ans / 2 << endl << I + 1 << ' ' << J + 1 << endl;

    return 0;
}
