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


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];
vector<int> g[50001];


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];
}

const int M = 1000000009;
const int P = 424243;
const int M1 = 1000000007;
const int P1 = 1000003;
unordered_map<int, int> hf;
vector<int> h;
vector<int> h1;
int p[300001];
int p1[300001];

int gethash(int l, int r) {
    return (h[r] - (l != 0 ? 1LL * h[l - 1] * p[r - l + 1] % M: 0) + M) % M;
}

int gethash1(int l, int r) {
    return (h1[r] - (l != 0 ? 1LL * h1[l - 1] * p1[r - l + 1] % M1: 0) + M1) % M1;
}


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 = 0;
    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;
    if (kur > 5001) {
        p[0] = 1;
        for (int i = 1; i <= 100; i++) {
            p[i] = (1LL * p[i - 1] * P) % M;
        }
        p1[0] = 1;
        for (int i = 1; i <= 100; i++) {
            p1[i] = (1LL * p1[i - 1] * P1) % M1;
        }
        int ans = 0;
        int l = 1, r = 2;
        for (int i = 0; i < kur; i++) {
            if (c[i]) {
                c[i]--;
                int s = a[i];
                while (s != c[i]) {
                    g[i].push_back(s);
                    s = pr[s][0];
                }
                g[i].push_back(c[i]);
                vector<int> gt;
                s = b[i];
                while (s != c[i]) {
                    gt.push_back(s);
                    s = pr[s][0];
                }
                reverse(gt.begin(), gt.end());
                for (int j = 0; j < (int)gt.size(); j++) {
                    g[i].push_back(gt[j]);
                }
                c[i]++;
            } else {
                int s = b[i];
                while (s != a[i]) {
                    g[i].push_back(s);
                    s = pr[s][0];
                }
                g[i].push_back(a[i]);
            }
            h.resize((int)g[i].size());
            for (int j = 0; j < (int)g[i].size(); j++) {
              //  cout << g[i][j] + 1 << ' ';
                h[j] = ((j != 0 ? (1LL * h[j - 1] * P) % M: 0) + g[i][j] + 1) % M;
            }
            h1.resize((int)g[i].size());
            for (int j = 0; j < (int)g[i].size(); j++) {
              //  cout << g[i][j] + 1 << ' ';
                h1[j] = ((j != 0 ? (1LL * h1[j - 1] * P1) % M1: 0) + g[i][j] + 1) % M1;
            }
            //cout << endl;
            for (int j = 0; j < (int)g[i].size(); j++) {
                for (int t = j + 1 + ans; t < (int)g[i].size(); t++) {
                    int x = gethash(j, t);
                    int x1 = gethash1(j, t);
                    int x2 = ((1LL * x * P1) % M + x1) % M;
                    //cout << x <<  ' ' << j << ' ' << t << ' ' << i + 1 << endl;
                    if (hf.find(x2) != hf.end()) {

                        if (ans < t - j) {
                            ans = t - j;
                            l = hf[x2];
                            r = i + 1;
                        }
                    } else {
                        hf[x2] = i + 1;
                    }
                }
            }
            reverse(g[i].begin(), g[i].end());
            for (int j = 0; j < (int)g[i].size(); j++) {
                //cout << g[i][j] + 1 << ' ';
                h[j] = ((j != 0 ? (1LL * h[j - 1] * P) % M: 0) + g[i][j] + 1) % M;
            }
             for (int j = 0; j < (int)g[i].size(); j++) {
                //cout << g[i][j] + 1 << ' ';
                h1[j] = ((j != 0 ? (1LL * h1[j - 1] * P1) % M1: 0) + g[i][j] + 1) % M1;
            }
            //cout << endl;
            for (int j = 0; j < (int)g[i].size(); j++) {
                for (int t = j + 1 + ans; t < (int)g[i].size(); t++) {
                    int x = gethash(j, t);
                    int x1 = gethash1(j, t);
                    int x2 = ((1LL * x * P1) % M + x1) % M;
                    if (hf.find(x2) != hf.end()) {

                        if (ans < t - j) {
                            ans = t - j;
                            l = hf[x2];
                            r = i + 1;
                        }
                    } else {
                        hf[x2] = i + 1;
                    }
                }
            }
        }
        cout << ans << endl;
        cout << l << ' ' << r << endl;
        return 0;
    }
    int ans = 0;
    int l = 2, r = 1;
    int tt = 0;
    for (int i = 0; i < kur; i++) {
        for (int j = i + 1; j < kur; j++) {
            tt++;
            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;
            }
        }
    }
    cout << ans << endl;
    cout << l << ' ' << r << endl;
    return 0;
}


