#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

typedef long long ll;

const int N = 2e5;
const int K = 20;

int n, k;
vector<int> g[N];
int depth[N], en[N], ex[N], tin[N];
pair<int, int> table[K][10 * N];
int logK[10 * N];
int T = 0, C = 0;

void clear() {
    for (int i = 0; i < n; i++) g[i].clear();
    C = 0;
    T = 0;
}

void build() {
    for (int k = 0; (1 << (k + 1)) <= C; k++) {
        for (int i = 0; i < C; i++) {
            table[k + 1][i] = min(table[k][i], table[k][i + (1 << k)]);
        }
    }
    for (int i = 2; i <= C; i++) {
        logK[i] = logK[i >> 1] + 1;
    }
}

void dfs(int v, int p) {
    en[v] = T++;
    depth[v] = depth[p] + 1;

    tin[v] = C;
    table[0][C++] = {depth[v], v};

    for (int u : g[v]) {
        if (u != p) {
            table[0][C++] = {depth[v], v};
            dfs(u, v);
            table[0][C++] = {depth[v], v};
        }
    }

    ex[v] = T++;
    table[0][C++] = {depth[v], v};
}

inline bool isAnc(int a, int b) {
    return en[a] <= en[b] && ex[b] <= ex[a];
}

inline int getlca(int a, int b) {
    int l = tin[a], r = tin[b];
    if (l > r) swap(l, r);
    int len = logK[r - l + 1];
    return min(table[len][l], table[len][r - (1 << len) + 1]).se;
}

inline int dist(int a, int b) {
    int lca = getlca(a, b);
    return depth[a] + depth[b] - 2 * depth[lca];
}

bool cmpdepth(int a, int b) {
    return depth[a] < depth[b];
}

inline bool onpath(int a, int b, int v) {
   return dist(a, v) + dist(v, b) == dist(a, b);
}

int get(int a, int b, int u, int v) {
    vector<int> lcas(4);
    lcas[0] = getlca(a, u);
    lcas[1] = getlca(a, v);
    lcas[2] = getlca(b, u);
    lcas[3] = getlca(b, v);
    sort(lcas.begin(), lcas.end(), cmpdepth);
    lcas.erase(unique(lcas.begin(), lcas.end()), lcas.end());

    for (int i = (int)lcas.size() - 1; i >= 0; i--) {
        if (!onpath(a, b, lcas[i]) || !onpath(v, u, lcas[i])) {
            lcas.erase(lcas.begin() + i);
        }
    }

    if (lcas.size() <= 1) {
        return 0;
    } else if (lcas.size() == 2) {
        return dist(lcas[0], lcas[1]);
    } else if (lcas.size() == 3) {
        return dist(lcas[1], lcas[2]);
    }
    assert(false);
}

void solve() {
    for (int i = 1; i <= n - 1; i++) {
        int p;
        scanf("%d", &p);
        --p;
        g[p].push_back(i);
        g[i].push_back(p);
    }

    dfs(0, 0);
    build();


    vector< pair<int, int> > q(k);
    for (int i = 0; i < k; i++) {
        scanf("%d%d", &q[i].fi, &q[i].se);
        --q[i].fi, --q[i].se;
    }

    int ans = 0;
    int ansa = 0, ansb = 1;
    for (int i = 0; i < k; i++) {
        for (int j = 0; j < i; j++) {
            int cur = get(q[i].fi, q[i].se, q[j].fi, q[j].se);
            if (ans < cur) {
                ans = cur;
                ansa = i;
                ansb = j;
            }
        }
    }

    printf("%d\n%d %d\n", ans, ansa + 1, ansb + 1);
}

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

    while (scanf("%d%d", &n, &k) == 2) {
        clear();
        solve();
    }
}
