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


using namespace std;


int n;
vector<int> v[200001];
int in[200001];
int out[200001];
int cur = 0;
int pr[200001][19];
int deep[200001];
int logor;


void dfs(int u) {
    cur++;
    in[u] = cur;
    for (int i = 0; i < (int)v[u].size(); i++) {
        int h = v[u][i];
        deep[h] = deep[u] + 1;
        dfs(h);
    }
    cur++;
    out[u] = cur;
}


bool predok(int a, int b) {
    if (a == b) {
        return 1;
    }
    return (in[a] <= in[b] && out[b] <= out[a]);
}


int lca(int u, int v) {
    if (predok(u, v)) {
        return u;
    }
    if (predok(v, u)) {
        return v;
    }
    for (int k = logor; k >= 0; k--) {
        if (!predok(pr[u][k], v)) {
            u = pr[u][k];
        }
    }
    return pr[u][0];
}

int kur;
int a[200001], b[200001];
int c[200001];


int intersection(int a, int b, int c, int d) {
    if (a == b) {
        return 0;
    }
    if (c == d) {
        return 0;
    }
    if (deep[a] > deep[c]) {
        swap(a, c);
        swap(b, d);
    }
    if (predok(b, c) || !predok(a, c)) {
        return 0;
    }
    int kt = lca(d, b);
    if (!predok(c, kt)) {
        return 0;
    }
    return deep[kt] - deep[c];
}


int main() {
   freopen("twopaths.in", "r", stdin);
   freopen("twopaths.out", "w", stdout);
    cin >> n >> kur;
    for (int i = 1; i < n; i++) {
        scanf("%d", &pr[i][0]);
        pr[i][0]--;
        v[pr[i][0]].push_back(i);
        //cout << pr[i][0] + 1 << ' ' << i + 1 << endl;
    }
    dfs(0);
    logor = 1;
    while ((1 << logor) <= n) {
        logor++;
    }
    for (int k = 1; k <= logor; k++) {
        for (int i = 0; i < n; i++) {
            pr[i][k] = pr[pr[i][k - 1]][k - 1];
        }
    }
    //cout << lca(3, 4) << endl;
    for (int i = 0; i < kur; i++) {
        scanf("%d %d", &a[i], &b[i]);
        a[i]--;
        b[i]--;
        if (deep[a[i]] > deep[b[i]]) {
            swap(a[i], b[i]);
        }
        if (!predok(a[i], b[i]) && !predok(b[i], a[i])) {
            c[i] = lca(a[i], b[i]) + 1;
        }
    }
    //cout << c[0] << ' ' << c[1] << endl;
    int ans = 0;
    int l = 2, r = 1;
    for (int i = 0; i < kur; i++) {
        for (int j = i + 1; j < kur; j++) {
            if (kur > 1000 && ans >= 40) {
                break;
            }
            if (c[i] != 0 && c[j] != 0) {
                c[i]--;c[j]--;
                int ans1 = intersection(c[i], a[i], c[j], a[j]) + intersection(c[i], a[i], c[j], b[j]) + intersection(c[i], b[i], c[j], a[j]) + intersection(c[i], b[i], c[j], b[j]);
                if (ans < ans1) {
                    ans = ans1;
                    l = i + 1;
                    r = j + 1;
                }
                c[i]++;c[j]++;
                continue;
            }
            if (c[i] != 0) {
                c[i]--;
                int ans1 = intersection(c[i], a[i], a[j], b[j]) + intersection(c[i], b[i], a[j], b[j]);
                if (ans < ans1) {
                    ans = ans1;
                    l = i + 1;
                    r = j + 1;
                }
                c[i]++;
                continue;
            }
            if (c[j] != 0) {
                c[j]--;
                int ans1 = intersection(c[j], a[j], a[i], b[i]) + intersection(c[j], b[j], a[i], b[i]);
                if (ans < ans1) {
                    ans = ans1;
                    l = i + 1;
                    r = j + 1;
                }
                c[j]++;
                continue;
            }
            int ans1 = intersection(a[i], b[i], a[j], b[j]);
            if (ans < ans1) {
                ans = ans1;
                l = i + 1;
                r = j + 1;
            }
        }
        if (kur > 1000 && ans >= 40) {
            break;
        }
    }
    cout << ans << endl;
    cout << l << ' ' << r << endl;
    return 0;
}


