#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <string>
#include <set>

using namespace std;

const int NMAX = 4000;

int pref[NMAX];
pair <int, int> couriers[NMAX];
vector <pair <int, int> > way[NMAX];
vector <int> edge[NMAX][NMAX];
vector <int> edl[NMAX];
vector <pair <int, int> > c;
int been[NMAX];
int r[NMAX][NMAX];

void dfs(int v, int u, int i, int n) {
    been[v] = 1;
    if (v == u) {
        for (int q = 0; q < c.size(); q++) {
            edge[min(c[q].first, c[q].second)][max(c[q].first, c[q].second)].push_back(n);
        }
    }
    else {
        for (int j = 0; j < edl[v].size(); j++) {
            if (been[edl[v][j]] != 1) {
                c.push_back(make_pair(v, edl[v][j]));
                dfs(edl[v][j], u, i, n);
                c.pop_back();
            }
        }
    }
}

int main() {
    freopen("twopaths.in", "r", stdin);
    freopen("twopaths.out", "w", stdout);
    int n, k, x, y;
    cin >> n >> k;
    for (int i = 1; i < n; i++) {
        cin >> x;
        pref[i] = x - 1;
        edl[x - 1].push_back(i);
        edl[i].push_back(x - 1);
    }
    for (int i = 0; i < k; i++) {
        cin >> x >> y;
        couriers[i] = make_pair(x - 1, y - 1);
        dfs(x - 1, y - 1, x - 1, i);
        for (int q = 0; q < n; q++) {
            been[q] = 0;
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            for (int q1 = 0; q1 < edge[i][j].size(); q1++) {
                for (int q2 = 0; q2 < edge[i][j].size(); q2++) {
                    if (q1 != q2) {
                        r[edge[i][j][q1]][edge[i][j][q2]] += 1;
                    }
                }
            }
        }
    }
    int maxx = 0;
    int rem1 = 1, rem2 = 2;
    for (int i = 0; i < k; i++) {
        for (int j = 0; j < k; j++) {
            if (r[i][j] > maxx) {
                maxx = r[i][j];
                rem1 = i + 1;
                rem2 = j + 1;
            }
        }
    }
    cout << maxx << endl;
    cout << rem1 << " " << rem2;
    fclose(stdin);
    fclose(stdout);
}
