#include <bits/stdc++.h>
#define fr(i, n) for (int i = 0; i < n; i++)
#define frab(i, a, b) for (int i = a; i < b; i++)
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 1e3 + 1;
const int INF = 2e9 + 1;

int a1[N], a2[N];
vector <int> g[N], revg[N];
int dist[N];
//bool used1[N], used2[N];
int par[N];

void dfs1(int v, int dst) {
    dist[v] = dst + 1;
    fr(i, g[v].size())
        dfs1(g[v][i], dst + 1);
}

set <int> used1[N];

bitset <100001> bs[N], tmp;

int main() {
    freopen("twopaths.in", "r", stdin);
    freopen("twopaths.out", "w", stdout);
    int n, k;
    cin >> n >> k;
    fr(i, n - 1) {
        int v;
        cin >> v;
        v--;
        g[v].pb(i + 1);
        par[i + 1] = v;
    }
    fr(i, k) {
        cin >> a1[i] >> a2[i];
        a1[i]--, a2[i]--;
    }

    dfs1(0, 0);
    //fr(i, n)
        //cout << dist[i] << endl;
    int ans = -2, ans1, ans2;

    fr(i1, k) {
        int mn1 = min(dist[a1[i1]], dist[a2[i1]]);
        //cout << mn1 << endl;
        int t1 = a1[i1], t2 = a2[i1];
        while (dist[t1] > mn1) {
            //used1[t1].insert(i1);
            bs[i1].set(t1);
            bs[i1].set(par[t1]);
            //used1[par[t1]].insert(i1);// = used1[par[t1]] = true;
            t1 = par[t1];
        }
        while (dist[t2] > mn1) {
            //used1[t2] = used1[par[t2]] = true;
            //used1[t2].insert(i1);
            //used1[par[t2]].insert(i1);//
            bs[i1].set(t2);
            bs[i1].set(par[t2]);
            t2 = par[t2];
        }

        while (t1 != t2) {
//            used1[t1].insert(i);
//            used1[par[t1]].insert(i);
//            used1[t2].insert(i);
//            used1[par[t2]].insert(i);
            bs[i1].set(t1);
            bs[i1].set(par[t1]);
            bs[i1].set(t2);
            bs[i1].set(par[t2]);
            t1 = par[t1], t2 = par[t2];
        }
    }
    ans = 0, ans1 = 0, ans2 = 1;
    fr(i1, k)
        frab(i2, i1 + 1, k) {
            tmp = bs[i1] & bs[i2];
            int temp = (int)tmp.count() - 1;
            if (ans < temp)
                ans = temp, ans1 = i1, ans2 = i2;
            //ans = max(ans, (int)tmp.count() - 1);
        }

    cout << ans << endl << ans1 + 1 << " " << ans2 + 1;

}
