#include <bits/stdc++.h>

//#define int long long
#define f first
#define s second
#define all(a) (a).begin(), (a).end()
#define len(a) (int)(a).size()
#define pb push_back
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
//#define endl '\n'

using namespace std;

int n, k;
vector<vector<int> > g;
map<int, vector<int> > m;
vector<int> used;

bool dfs(int u, int w, int k1) {
    used[u] = 1;
    forn(i, len(g[u])) {
        int v = g[u][i];
        if (!used[v]) {
            if (v == w || dfs(v, w, k1)) {
                int a = min(u, v) * n + max(u, v);
                if (m.find(a) == m.end()) {
                    m[a] = {k1};
                }
                else {
                    m[a].pb(k1);
                }
                return 1;
            }
        }
    }
}

int main()
{
    freopen("twopaths.in", "r", stdin);
    freopen("twopaths.out", "w", stdout);
    cin >> n >> k;
    g.resize(n);
    forn(i, n - 1) {
        int u;
        cin >> u;
        g[u - 1].pb(i + 1);
        g[i + 1].pb(u - 1);
    }

    forn(i, k) {
        int u, v;
        cin >> u >> v;
        u --; v --;
        used.clear();
        used.resize(n, 0);
        dfs(u, v, i);
    }
    vector<vector<int> > cnt(k, vector<int> (k, 0));
    for (auto it = m.begin(); it != m.end(); ++it) {
        vector<int> k1 = m[it->f];
        for (int i = 0; i < len(k1); ++i) {
            for (int j = i + 1; j < len(k1); ++j) {
                cnt[k1[i]][k1[j]] ++;
                cnt[k1[j]][k1[i]] ++;
            }
        }
    }
    int ans = -1, ans1, ans2;
    forn(i, k) {
        forn(j, k) {
            if (cnt[i][j] > ans) {
                ans = cnt[i][j];
                ans1 = i;
                ans2 = j;
            }
        }
    }
    if (ans1 == 0) {
        cout << "1\n2 1";
        return 0;
    }
    cout << ans << '\n' << ans1 + 1 << ' ' << ans2 + 1;
    return 0;
}
