#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e5 + 5;
const int LOG = 18;

int n, k;
vector<int> graph[maxn];
int jump[LOG + 1][maxn];
int tin[maxn], tout[maxn];
int timer = 0;
int h[maxn];
int parent[maxn];
pair<int, int> paths[maxn];

void dfs(int v, int p) {
    if (p == -1) jump[0][v] = v;
    else jump[0][v] = p;
    for (int i = 1; i <= LOG; i++) {
        jump[i][v] = jump[i - 1][jump[i - 1][v]];
    }
    parent[v] = p;
    h[v] = ((p == -1) ? 0: h[p] + 1);
    tin[v] = timer++;
    for (auto u: graph[v]) {
        if (u != p) dfs(u, v);
    }
    tout[v] = timer++;
}

bool ancestor(int p, int v) {
    return tin[p] <= tin[v] && tout[v] <= tout[p];
}

int get_lca(int v, int u) {
    if (ancestor(v, u)) return v;
    if (ancestor(u, v)) return u;
    for (int i = LOG; i >= 0; i--) {
        int t = jump[i][v];
        if (!ancestor(t, u)) v = t;
    }
    return jump[0][v];
}

int g(int p1, int v1, int p2, int v2) {
    if (!ancestor(p1, p2)) {
        swap(p1, p2);
        swap(v1, v2);
    }
    if (!ancestor(p1, p2)) return 0;
    int lca = get_lca(v1, v2);
    return max(0, h[lca] - h[p2]);
}

int f(pair<int, int> a, pair<int, int> b) {
    int ans = 0;
    int v1 = a.first;
    int u1 = a.second;
    int v2 = b.first;
    int u2 = b.second;
    int p1 = get_lca(v1, u1);
    int p2 = get_lca(v2, u2);
    ans += g(p1, v1, p2, v2);
    ans += g(p1, u1, p2, v2);
    ans += g(p1, v1, p2, u2);
    ans += g(p1, u1, p2, u2);
    return ans;
}

map< pair<int, int>, int> pairs;

void solve_smallh() {
    int ans = 0;
    int x = 0, y = 1;
    for (int iter = 0; iter < k; iter++) {
        int a, b;
        tie(a, b) = paths[iter];
        vector<int> v;
        int lca = get_lca(a, b);
        while (a != lca) {
            v.push_back(a);
            a = parent[a];
        }
        vector<int> tmp;
        while (b != lca) {
            tmp.push_back(b);
            b = parent[b];
        }
        tmp.push_back(b);
        reverse(tmp.begin(), tmp.end());
        for (auto i: tmp) {
            v.push_back(i);
        }
        for (int i = 0; i < v.size(); i++) {
            for (int j = 0; j < v.size(); j++) {
                int cnt = abs(i - j);
                if (cnt <= ans) continue;
                auto tmp = make_pair(v[i], v[j]);
                if (pairs.find(tmp) != pairs.end()) {
                    ans = cnt;
                    x = pairs[tmp];
                    y = iter;
                } else {
                    pairs[tmp] = iter;
                }
            }
        }
    }
    printf("%d\n%d %d\n", ans, x + 1, y + 1);
}

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

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

    dfs(0, -1);

    for (int i = 0; i < k; i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        paths[i] = {a - 1, b - 1};
    }

    if (*max_element(h, h + n) <= 30) {
        solve_smallh();
        return 0;
    }

    int ans = 0;
    int x = 0, y = 1;
    for (int i = 0; i < k; i++) {
        for (int j = i + 1; j < k; j++) {
            int tmp = f(paths[i], paths[j]);
            if (tmp > ans) {
                ans = tmp;
                x = i; y = j;
            }
        }
    }

    printf("%d\n%d %d\n", ans, x + 1, y + 1);
}

