#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 goup(int v, int step) {
    for (int i = LOG - 1; i >= 0; --i) {
        if ((1 << i) <= step) v = p[i][v], step -= (1 << i);
    }
    return v;
}

int inters(int up1, int down1, int up2, int down2) {
    //cout << up1 << "->" << down1 << endl << up2 << "->" << down2 << endl;
    int lg = max(d[up1], d[up2]), rg = min(d[down1], d[down2]);
    //cout << lg << ' ' << rg << endl;

    //cout << endl << endl;
    if (lg >= rg) return 0;
    if (d[down1] > rg) down1 = goup(down1, d[down1] - rg);
    if (d[down2] > rg) down2 = goup(down2, d[down2] - rg);
    for (int i = LOG - 1; i >= 0; --i) {
        if (d[down1] - (1 << i) > lg && p[i][down1] != p[i][down2]) {
            down1 = p[i][down1];
            down2 = p[i][down2];
        }
    }
    if (down1 != down2) {
        down1 = p[0][down1];
        down2 = p[0][down2];
    }
    //cout << down1 << ' ' << down2 << endl;

    //cout << endl << endl;
    return d[down1] - lg;
}

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 y = x + 1; y <= k; ++y) {
            int xa = wa[x], xb = wb[x], xlca = getLca(xa, xb);
            int ya = wa[y], yb = wb[y], ylca = getLca(ya, yb);
            int cur = inters(xlca, xa, ylca, ya) + inters(xlca, xa, ylca, yb) + inters(xlca, xb, ylca, ya) + inters(xlca, xb, ylca, yb);
            if (cur > ans) {
                ans = cur;
                aa = x, ab = y;
            }
        }
    }
    cout << ans << '\n' << aa << ' ' << ab;
    return 0;
}