#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 = 4001;
const int maxk = 1001;
int n, k;
vector<int> g[maxn];
int a[maxk], b[maxk];
int tin[maxn], tout[maxn];
int par[maxn];
int T = 1;

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

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

vector<int> vec[maxn];
int u[maxk][maxk];

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;
        par[i] = p;
        g[p].pb(i);
    }
    dfs0(0);
    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 = 0; i < k; ++i) {
        int v;
        v = a[i];
        while (!isAnsestor(v, b[i]))
            vec[v].pb(i), v = par[v];
        v = b[i];
        while (!isAnsestor(v, a[i]))
            vec[v].pb(i), v = par[v];
    }
    for (int i = 0; i < n; ++i) {
        //cerr << i + 1 << " : ";
        for (int j = 1; j < (int)vec[i].size(); ++j) {
            //cerr << vec[i][j] + 1 << ' ';
            for (int t = 0; t < j; ++t) {
                ++u[vec[i][j]][vec[i][t]];
                ++u[vec[i][t]][vec[i][j]];
            }
        }
        //cerr << endl;
    }
    for (int i = 1; i < k; ++i)
        for (int j = 0; j < k; ++j)
            if (u[i][j] > mx)
                mx = u[i][j], I = i, J = j;
    cout << mx << '\n' << I + 1 << ' ' << J + 1;
    return 0;
}

/*
4 2
1 2 2
1 3
1 4
*/

