#include <bits/stdc++.h>

using namespace std;

const int max_n = 110;

vector <int> a[max_n];
int b[max_n];
int c[max_n];
int p[max_n];
bool vis[max_n][max_n];
bool vis1[max_n][max_n];
int n, k;


struct node {
    int in, out, up;
};
node t[max_n];
int deep[max_n];
int tin = 0;
int tout = 0;

bool pred(int u, int v) {
    return (t[u].in < t[v].in && t[u].out > t[v].out);
}

int Get(int x, int y, int a, int b) {
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            vis[i][j] = false;
            vis1[i][j] = false;
        }
    }
    int v = x;
    int u = y;
    while (v != u) {
        if (pred(u, v)) {
            vis[v][p[v]] = true;
            vis[p[v]][v] = true;
            v = p[v];
            continue;
        }
        if (pred(v, u)) {
            vis[u][p[u]] = true;
            vis[p[u]][u] = true;
            u = p[u];
            continue;
        }
        if (u != 0) {
            vis[u][p[u]] = true;
            vis[p[u]][u] = true;
            u = p[u];
            continue;
        }
        vis[v][p[v]] = true;
        vis[p[v]][v] = true;
        v = p[v];
    }
    v = a;
    u = b;
    while (v != u) {
        if (pred(u, v)) {
            vis1[v][p[v]] = true;
            vis1[p[v]][v] = true;
            v = p[v];
            continue;
        }
        if (pred(v, u)) {
            vis1[u][p[u]] = true;
            vis1[p[u]][u] = true;
            u = p[u];
            continue;
        }
        if (u != 0) {
            vis1[p[u]][u] = true;
            vis1[u][p[u]] = true;
            u = p[u];
            continue;
        }
        vis1[p[v]][v] = true;
        vis1[v][p[v]] = true;
        v = p[v];
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (vis[i][j] && vis1[i][j]) {
                ans++;
            }
        }
    }
    return (ans / 2);
}

void dfs(int v, int d) {
    deep[v] = d;
    t[v].in = tin;
    tin++;
    for (int i = 0; i < a[v].size(); i++) {
        int u = a[v][i];
        dfs(u, d + 1);
    }
    t[v].out = tout;
    tout++;
}

int main()
{
    freopen ("twopaths.in", "r", stdin);
    freopen ("twopaths.out", "w", stdout);
    cin >> n >> k;
    p[0] = -1;
    for (int i = 0; i < n - 1; i++) {
        int x;
        cin >> x;
        a[x - 1].push_back(i + 1);
        p[i + 1] = x - 1;
    }
    for (int i = 0; i < k; i++) {
        cin >> b[i] >> c[i];
        b[i]--;
        c[i]--;
    }
    dfs(0, 0);
    int ans = -1;
    int ans_id = -1;
    int ans_id1 = -1;
    for (int i = 0; i < k; i++) {
        for (int j = i + 1; j < k; j++) {
            int s = Get(b[i], c[i], b[j], c[j]);
            if (s > ans) {
                ans = s;
                ans_id = i;
                ans_id1 = j;
            }
        }
    }
    cout << ans << endl;
    cout << ans_id + 1 << " " << ans_id1 + 1 << endl;
    return 0;
}
