#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define mkp make_pair
#define pb push_back
#define F first
#define S second
const int maxn = (int)1e5 + 100;
const int logn = 18;
const int maxk = 5002;
int n, k;
vector<int> g[maxn];
int a[maxk], b[maxk];
int up[logn][maxn];
int tin[maxn], tout[maxn];
int len[maxn];
int T = 1;
bool was[maxn];

void dfs0(int v, int h = 0) {
    tin[v] = T++;
    len[v] = h;
    for (int i = 0; i < (int)g[v].size(); ++i) {
        dfs0(g[v][i], h + 1);
    }
    tout[v] = T++;
}

void calc_up() {
    for (int l = 1; l < logn; ++l)
        for (int i = 0; i < n; ++i)
            up[l][i] = up[l - 1][up[l - 1][i]];
}

bool isAnsestor(int u, int v) {
    return (tin[u] <= tin[v] && tout[u] >= tout[v]);
}

int lca(int u, int v) {
    if (isAnsestor(u, v)) return u;
    if (isAnsestor(v, u)) return v;
    for (int l = logn - 1; l >= 0; --l)
        if (!isAnsestor(up[l][v], u))
            v = up[l][v];
    return up[0][v];
}

int Len(int u, int v) {
    return len[u] + len[v] - 2 * len[lca(u, v)];
}

int Len2(int u, int v, int lcauv) {
    return len[u] + len[v] - 2 * len[lcauv];
}

bool on_path(int v, int a, int b, int c) {
    if (isAnsestor(c, v) && isAnsestor(v, a)) return 1;
    if (isAnsestor(c, v) && isAnsestor(v, b)) return 1;
    return 0;
}

int 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;
        up[0][i] = p;
        g[p].pb(i);
    }
    dfs0(0, 0);
    calc_up();
    for (int i = 0; i < k; ++i) {
        scanf("%d %d", &a[i], &b[i]);
        --a[i], --b[i];
    }
    int mx = 0, I = 1, J = 0;
    for (int i = 1; i < k; ++i) {
        //cerr << i + 1 << endl;
        for (int j = 0; j < i; ++j) {
            int a1 = a[i], a2 = a[j];
            int b1 = b[i], b2 = b[j];
            int c1 = lca(a1, b1);
            int c2 = lca(a2, b2);
            int xa = lca(a1, a2);
            int cnt = 0;
            ////cerr << i + 1 << ' ' << j + 1 << " : \n";
            ////cerr << "  " << a1 + 1 << ' ' << b1 + 1 << ' ' << c1 + 1 << '\n';
            ////cerr << "  " << a2 + 1 << ' ' << b2 + 1 << ' ' << c2 + 1 << '\n';
            ////cerr << "  xa " << xa + 1 << '\n';
            if (!on_path(xa, a1, b1, c1) || !on_path(xa, a2, b2, c2)) {
                ////cerr << "!on_path\n";
                continue;
            }
            int v = xa;
            for (int l = logn - 1; l >= 0; --l) {
                if (on_path(up[l][v], a1, b1, c1) && on_path(up[l][v], a2, b2, c2)) {
                    v = up[l][v];
                }
            }
            //cerr << v << endl;
            while (v != 0 && on_path(up[0][v], a1, b1, c1) && on_path(up[0][v], a2, b2, c2))
                v = up[0][v];
            //cerr << v << endl;
            cnt = Len(xa, v);
            if (cnt > mx) mx = cnt, I = i, J = j;
        }
        for (int j = 0; j < i; ++j) {
            int a1 = a[i], a2 = a[j];
            int b1 = b[i], b2 = b[j];
            int c1 = lca(a1, b1);
            int c2 = lca(a2, b2);
            int xb = lca(b1, b2);
            int cnt = 0;
            ////cerr << i + 1 << ' ' << j + 1 << " : \n";
            ////cerr << "  " << a1 + 1 << ' ' << b1 + 1 << ' ' << c1 + 1 << '\n';
            ////cerr << "  " << a2 + 1 << ' ' << b2 + 1 << ' ' << c2 + 1 << '\n';
            ////cerr << "  xb " << xb + 1 << '\n';
            if (!on_path(xb, a1, b1, c1) || !on_path(xb, a2, b2, c2)) {
                ////cerr << "!on_path\n";
                continue;
            }
            int v = xb;
            for (int l = logn - 1; l >= 0; --l) {
                if (on_path(up[l][v], a1, b1, c1) && on_path(up[l][v], a2, b2, c2)) {
                    v = up[l][v];
                }
            }
            //cerr << v << endl;
            while (v != 0 && on_path(up[0][v], a1, b1, c1) && on_path(up[0][v], a2, b2, c2))
                v = up[0][v];
            //cerr << v << endl;
            cnt = Len(xb, v);
            if (cnt > mx) mx = cnt, I = i, J = j;
        }
        for (int j = 0; j < i; ++j) {
            int a1 = a[i], a2 = a[j];
            int b1 = b[i], b2 = b[j];
            int c1 = lca(a1, b1);
            int c2 = lca(a2, b2);
            int xab = lca(a1, b2);
            int cnt = 0;
            ////cerr << i + 1 << ' ' << j + 1 << " : \n";
            ////cerr << "  " << a1 + 1 << ' ' << b1 + 1 << ' ' << c1 + 1 << '\n';
            ////cerr << "  " << a2 + 1 << ' ' << b2 + 1 << ' ' << c2 + 1 << '\n';
            ////cerr << "  xab " << xb + 1 << '\n';
            if (!on_path(xab, a1, b1, c1) || !on_path(xab, a2, b2, c2)) {
                ////cerr << "!on_path\n";
                continue;
            }
            int v = xab;
            for (int l = logn - 1; l >= 0; --l) {
                if (on_path(up[l][v], a1, b1, c1) && on_path(up[l][v], a2, b2, c2)) {
                    v = up[l][v];
                }
            }
            //cerr << v << endl;
            while (v != 0 && on_path(up[0][v], a1, b1, c1) && on_path(up[0][v], a2, b2, c2))
                v = up[0][v];
            //cerr << v << endl;
            cnt = Len(xab, v);
            if (cnt > mx) mx = cnt, I = i, J = j;
        }
        for (int j = 0; j < i; ++j) {
            int a1 = a[i], a2 = a[j];
            int b1 = b[i], b2 = b[j];
            int c1 = lca(a1, b1);
            int c2 = lca(a2, b2);
            int xba = lca(b1, a2);
            int cnt = 0;
            ////cerr << i + 1 << ' ' << j + 1 << " : \n";
            ////cerr << "  " << a1 + 1 << ' ' << b1 + 1 << ' ' << c1 + 1 << '\n';
            ////cerr << "  " << a2 + 1 << ' ' << b2 + 1 << ' ' << c2 + 1 << '\n';
            ////cerr << "  xba " << xb + 1 << '\n';
            if (!on_path(xba, a1, b1, c1) || !on_path(xba, a2, b2, c2)) {
                ////cerr << "!on_path\n";
                continue;
            }
            int v = xba;
            for (int l = logn - 1; l >= 0; --l) {
                if (v != 0 && on_path(up[l][v], a1, b1, c1) && on_path(up[l][v], a2, b2, c2)) {
                    v = up[l][v];
                }
            }
            //cerr << v << endl;
            while (v != 0 && on_path(up[0][v], a1, b1, c1) && on_path(up[0][v], a2, b2, c2))
                v = up[0][v];
            //cerr << v << endl;
            cnt = Len(xba, v);
            if (cnt > mx) mx = cnt, I = i, J = j;
        }
    }
    cout << mx << '\n' << I + 1 << ' ' << J + 1;
    return 0;
}

/*
4 2
1 2 2
1 3
1 4

99
*/

