#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define size(x) (int) x.size()
#define all(x) x.begin(), x.end()

const int maxn = 100005;
const int logn = 17;
const int inf = (int) 1e9;
const long long mod = (long long) 1e9 + 7;
const long long l_inf = (long long) 4e18;

int n, k;
vector<int> g[maxn];
pair<int, int> q[maxn];
int dep[maxn], tin[maxn], tout[maxn], timer = 0;
pair<int, int> ST[logn][2 * maxn];
int in[maxn], it = 0;
int pw[2 * maxn];
int best[3];

void dfs(int v) {
    tin[v] = timer++;
    ST[0][it] = mp(dep[v], v);
    in[v] = it++;
    for (int u : g[v]) {
        dep[u] = dep[v] + 1;
        dfs(u);
        ST[0][it++] = mp(dep[v], v);
    }
    tout[v] = timer++;
}

inline int lca(int v, int u) {
    if (in[v] > in[u])
        swap(v, u);
    int x = pw[in[u] - in[v] + 1];
    return min(ST[x][in[v]], ST[x][in[u] - (1 << x) + 1]).second;
}

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

inline bool inPath(int x, int v, int u) {
    int l = lca(v, u);
    return isParent(l, x) && (isParent(x, v) || isParent(x, u));
}

inline int getDist(int v, int u) {
    int l = lca(v, u);
    return dep[v] + dep[u] - 2 * dep[l];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    srand(566);

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

    cin >> n >> k;
    for (int i = 1; i < n; i++) {
        int p;
        cin >> p;
        g[--p].pb(i);
    }
    dfs(0);

    for (int h = 1; h < logn; h++)
        for (int i = 0; i + (1 << h) - 1 < it; i++)
            ST[h][i] = min(ST[h - 1][i], ST[h - 1][i + (1 << (h - 1))]);

    for (int i = 1; i < logn; i++)
        pw[1 << i] = i;
    for (int i = 1; i < 2 * maxn; i++)
        if (pw[i] == 0)
            pw[i] = pw[i - 1];

    for (int i = 0; i < k; i++) {
        cin >> q[i].first >> q[i].second;
        q[i].first--, q[i].second--;
    }

    for (int i = 0; i < k; i++) {
        for (int j = i + 1; j < k; j++) {
            int v[2][2] = { {q[i].first, q[i].second}, {q[j].first, q[j].second} };

            vector<int> x;
            for (int i1 = 0; i1 < 2; i1++) {
                for (int j1 = 0; j1 < 2; j1++) {
                    int l = lca(v[0][i1], v[1][j1]);
                    if (inPath(l, v[0][0], v[0][1]) && inPath(l, v[1][0], v[1][1]))
                        x.pb(l);
                }
            }

            int maxDist = 0;
            for (int i1 = 0; i1 < size(x); i1++)
                for (int j1 = i1 + 1; j1 < size(x); j1++)
                    maxDist = max(maxDist, getDist(x[i1], x[j1]));
            if (maxDist >= best[0]) {
                best[0] = maxDist;
                best[1] = i + 1;
                best[2] = j + 1;
            }
        }
    }

    cout << best[0] << '\n' << best[1] << ' ' << best[2];


    return 0;
}
