#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define point pair <int, int>
#define For(i, a, b) for(int i = a; i < b; ++i)
#define Out(i, a, b) for(int i = a - 1; i >= b; --i)
#define files(FileName) read(FileName); write(FileName)
#define read(FileName) freopen((FileName + ".in").c_str(), "r", stdin)
#define write(FileName) freopen((FileName + ".out").c_str(), "w", stdout)

using namespace std;

string FileName = "typing";

typedef long long base;

int n, k;
int TimeOff = 0;
int Deep[100001];
int Time[100001][2];
int up[100001][17];
int Ark[100001];
vector <int> edge[100001];
pair <int, int> arr[5001];

int dfs(int i, int D) {
    ++TimeOff;
    Deep[i] = D;
    Time[i][0] = TimeOff;
    for(int j: edge[i]) {dfs(j, D + 1); up[j][0] = i;}
    Time[i][1] = TimeOff;
    ++TimeOff;
}

bool In(int i, int j) {
    return Time[i][0] <= Time[j][0] && Time[j][1] <= Time[i][1];
}

bool OnWay(int A, int B, int C) {
    return In(A, B) && In(B, C);
}

void Sons() {
    For(j, 1, 17) {
        For(i, 0, n) {
            up[i][j] = up[up[i][j - 1]][j - 1];
        }
    }
}

int LCA(int i, int j) {
    if (In(j, i))  return j;
    if (In(i, j))  return i;
    int M = 16;
    while (M != -1) {
        if (!In(up[j][M], i)) {
            j = up[j][M];
        }
        --M;
    }
    return up[j][0];
}

int check(int i, int j) {
    int B1 = LCA(arr[i].x, arr[j].x);
    int B2 = LCA(arr[i].x, arr[j].y);
    int A1 = LCA(arr[i].y, arr[j].x);
    int A2 = LCA(arr[i].y, arr[j].y);
    int Ans = 0;
    //cout << B1 << ' ' << B2 << ' ' << Ark[i] << ' ' << Ark[j] << endl;
    if (min(Deep[B1], Deep[B2]) >= max(Deep[Ark[i]], Deep[Ark[j]])) {
        Ans += abs(Deep[B1] - Deep[B2]);
    }
    //cout << A1 << ' ' << A2 << ' ' << Ark[i] << ' ' << Ark[j] << endl;
    //cout << Ans << endl;
     if (min(Deep[A1], Deep[A2]) >= max(Deep[Ark[i]], Deep[Ark[j]])) {
        Ans += abs(Deep[A1] - Deep[A2]);
    }
    //cout << Ans << endl;
    return max(Ans, 0);
}
int main() {
    ios::sync_with_stdio(false);
    files(FileName);
    cin >> n >> k;
    For(i, 1, n) {
        int A; cin >> A; --A;
        edge[A].pb(i);
    }
    dfs(0, 0); Sons();
    For(i, 0, k) {
        int A, B; cin >> A >> B; --A; --B;
        arr[i] = {A, B};
        Ark[i] = LCA(A, B);
    }
    int Ans = -1, L = 0, R = 0;
    For(i, 0, k) {
        For(j, i + 1, k) {
            int NA = 0;
            if (Ark[i] < Ark[j]) {
                NA = check(i, j);
            } else {
                NA = check(j, i);
            }
            //cout << i + 1 << ' ' << j + 1 << ' ' << NA << endl;
            if (Ans < NA) {
                Ans = NA;
                L = i;
                R = j;
            }
        }
    }
    cout << Ans << endl;
    cout << L + 1 << ' ' << R + 1 << endl;
}
