#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <set>
#include <map>
#include <cmath>

using namespace std;

const int LOG = 18;
const int N = (1 << LOG);

vector<int> gr[N];
int p[LOG][N];
int d[N];
int wa[N], wb[N];

int tin[N], tout[N];
int timer = 0;
bool used[N];

void dfs(int v) {
    tin[v] = ++timer;
    for (int to : gr[v]) {
        d[to] = d[v] + 1;
        p[0][to] = v;
        dfs(to);
    }
    tout[v] = ++timer;
}

bool isPar(int a, int b) {
    return (tin[a] <= tin[b] && tout[a] >= tout[b]);
}

int getLca(int a, int b) {
    if (isPar(a, b)) return a;
    if (isPar(b, a)) return b;
    for (int i = LOG - 1; i >= 0; --i) {
        if (p[i][a] != 0 && !isPar(p[i][a], b)) a = p[i][a];
    }
    return p[0][a];
}

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

    int n, k;
    scanf("%d%d", &n, &k);
    for (int i = 2; i <= n; ++i) {
        int par;
        scanf("%d", &par);
        gr[par].push_back(i);
    }
    dfs(1);
    for (int lg = 1; lg < LOG; ++lg) {
        for (int i = 1; i <= n; ++i) {
            p[lg][i] = p[lg - 1][p[lg - 1][i]];
        }
    }
    for (int i = 1; i <= k; ++i) {
        scanf("%d%d", &wa[i], &wb[i]);
    }
    int ans = 0;
    int aa = 1, ab = 2;
    for (int x = 1; x < k; ++x) {
        for (int i = 1; i <= n; ++i) used[i] = false;
        int ca = wa[x], cb = wb[x];
        int lca = getLca(ca, cb);
        while (ca != lca) {
            used[ca] = true;
            ca = p[0][ca];
        }
        while (cb != lca) {
            used[cb] = true;
            cb = p[0][cb];
        }
        for (int y = x + 1; y <= k; ++y) {
            int cur = 0;
            int cca = wa[y], ccb = wb[y];
            int clca = getLca(cca, ccb);
            while (cca != clca) {
                cur += used[cca];
                cca = p[0][cca];
            }
            while (ccb != clca) {
                cur += used[ccb];
                ccb = p[0][ccb];
            }
            if (cur > ans) {
                ans = cur;
                aa = x, ab = y;
            }
        }
    }
    cout << ans << '\n' << aa << ' ' << ab;
    return 0;
}