#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

#define fst first
#define snd second
#define sz(v_) (int((v_).size()))

using namespace std;

const int maxn = 5e5;

int n, k;
vector<int> g[maxn];
int de[maxn];
int up[maxn][30];
int tin[maxn];
int tout[maxn];
int slca[maxn];

void dfs(int v, int d = 0)
{
    de[v] = d;
    for (auto &to: g[v]) {
        dfs(to, d+1);
    }
}
pair<int, int> ks[maxn];

int la(int a, int u)
{
    for (int l = 29; l >= 0; --l) {
        if ((1<<l) <= u) {
            a = up[a][l];
            u -= (1<<l);
        }
    }
    return a;
}

int lca(int a, int b)
{
    if (de[a] < de[b]) {
        swap(a, b);
    }
    a = la(a, de[a]-de[b]);
    if (a == b) {
        return a;
    }
    for (int l = 29; l >= 0; --l) {
        if (up[a][l] != up[b][l]) {
            a = up[a][l];
            b = up[b][l];
        }
    }
    return up[a][0];
}

bool isp(int a, int b)
{
    return lca(a, b) == a;
}

int inter(int a, int b, int c, int d)
{
    //cout << a+1 << ' ' << b+1 << ' ' << c+1 << ' ' << d+1 << endl;
    int y = lca(a, c);
    //cout << y+1 << endl;
    if (!isp(b, y) || !isp(d, y)) {
        return 0;
    }
    int e = b;
    if (isp(b, d)) {
        e = d;
    }
    //cout << e+1 << endl;
    return de[y]-de[e];
}

int main()
{
    freopen("twopaths.in", "r", stdin);
    freopen("twopaths.out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n >> k;
    up[0][0] = 0;
    for (int i = 1; i < n; ++i) {
        int a;
        cin >> a;
        --a;
        up[i][0] = a;
        g[a].push_back(i);
    }
    dfs(0);
    for (int l = 1; l < 30; ++l) {
        for (int a = 0; a < n; ++a) {
            up[a][l] = up[up[a][l-1]][l-1];
        }
    }
    for (int i = 0; i < k; ++i) {
        cin >> ks[i].fst >> ks[i].snd;
        --ks[i].fst;
        --ks[i].snd;
        slca[i] = lca(ks[i].fst, ks[i].snd);
    }
    int res = 0, ra = 0, rb = 1;
    for (int i = 0; i < k; ++i) {
        int a = ks[i].fst, b = ks[i].snd;
        int c = slca[i];
        for (int j = i+1; j < k; ++j) {
            int q = ks[j].fst, p = ks[j].snd;
            int u = slca[j];
            int len = inter(a, c, q, u)+inter(a, c, p, u)+inter(b, c, q, u)+inter(b, c, p, u);
            if (len > res) {
                res = len;
                ra = i;
                rb = j;
            }
        }
    }
    cout << res << '\n' << ra+1 << ' ' << rb+1 << '\n';
    return 0;
}
