#include <bits/stdc++.h>
#define pb push_back
#define ins insert
#define mkp make_pair
#define mt make_tuple
using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;

const int N = 800000 + 5;



int n, k;

vector<int> neig[N];
int parent[N];
int as[N];
int bs[N];
int cs[N];
int first[N];
int depth[N];
int way[N];
int wayCnt = 0;
pii tree[4 * N];

void buildTree(int v, int l, int r) {
    if (l == r) {
        tree[v] = mkp(depth[way[l]], way[l]);
    } else {
        buildTree(v * 2, l, (l + r) / 2);
        buildTree(v * 2 + 1, (l + r) / 2 + 1, r);
        tree[v] = min(tree[v * 2], tree[v * 2 + 1]);
    }
}

pii getTree(int v, int L, int R, int l, int r) {
    if (l > R || L > r)
        return mkp(1000000000, 1000000000);
    if (l >= L && r <= R)
        return tree[v];
    return min(
            getTree(v * 2, L, R, l, (l + r) / 2),
            getTree(v * 2 + 1, L, R, (l + r) / 2 + 1, r)
    );
}

int getPredok(int a, int b) {
    return getTree(1, min(first[a], first[b]), max(first[a], first[b]), 0, wayCnt).second;

    int mini = 1000000000;
    int ans = 0;
    for (int i = min(first[a], first[b]); i <= max(first[a], first[b]); i++) {
        if (mini > depth[way[i]]) {
            ans = way[i];
            mini = depth[way[i]];
        }
    }
    return ans;
}



void dfsWay(int v, int d) {
    first[v] = wayCnt;
    depth[v] = d;
    way[wayCnt++] = v;
    for (auto it : neig[v]) {
        dfsWay(it, d + 1);
        way[wayCnt++] = v;
    }
}

int getCurr(int a, int b, int c, int d) {
    if (a == b || c == d)
        return 0;

    int pred = getPredok(a, c);
    return max(0, depth[pred] - max(depth[d], depth[b]));
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

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

    cin >> n >> k;

    for (int i = 1; i < n; i++) {
        cin >> parent[i];
        parent[i]--;
        neig[parent[i]].pb(i);
    }

    dfsWay(0, 0);

    buildTree(1, 0, wayCnt);

    memset(as, 0, sizeof(as));
    memset(bs, 0, sizeof(bs));
    memset(cs, 0, sizeof(cs));

    for (int i = 0; i < k; i++) {
        cin >> as[i] >> bs[i];
        as[i]--;
        bs[i]--;
        cs[i] = getPredok(as[i], bs[i]);
    }

    int maxi = 0, a = 0, b = 1;

    for (int i = 0; i < k; i++) {
        for (int z = i + 1; z < k; z++) {
            int curr = 0;
            curr += getCurr(as[i], cs[i], as[z], cs[z]);
            curr += getCurr(as[i], cs[i], bs[z], cs[z]);
            curr += getCurr(bs[i], cs[i], as[z], cs[z]);
            curr += getCurr(bs[i], cs[i], bs[z], cs[z]);
            if (curr > maxi) {
                maxi = curr;
                a = i;
                b = z;
            }
        }
    }

    cout << maxi << "\n" << a + 1 << " " << b + 1;
}