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

using namespace std;
vector<pair<int, int> > a[100000];
vector<int> path;
vector<int> ver;
vector <int> cur[1000];
int was[100000];
int sh = 0;
bool fd = false;
void dfs(int v) {
    //cout << v << endl;
    if (v == sh) {
        fd = true;
    }
    if (fd) {
        return;
    }
    was[v] = 1;
    //ver.push_back(v);
    //cout << "X";
    for (int i = 0; i < a[v].size() && !fd; i++) {
        if (was[a[v][i].second] == 0) {
            path.push_back(a[v][i].first);
            dfs(a[v][i].second);
            if (!fd) path.pop_back();
        }
    }
}
int main() {
    freopen("twopaths.in", "r", stdin);
    freopen("twopaths.out", "w", stdout);
    int n, k;
    cin >> n >> k;
    int x, y;
    int cnt = 0;
    for (int i = 1; i < n; i++) {
        cin >> x;
        x--;
        a[x].push_back(make_pair(cnt, i));
        a[i].push_back(make_pair(cnt, x));
        cnt++;
    }
    //cout << cnt << endl;
    for (int i = 0; i < k; i++) {
        for (int w = 0; w < n; w++) {
            was[w] = 0;
        }
        cin >> x >> y;
        x--;
        y--;
        sh = y;
        fd = false;
        dfs(x);
        for (int j = 0; j < path.size(); j++) {
            cur[i].push_back(path[j]);
        }
        path.clear();
    }
    int ans = 0;
    int i1 = 0;
    int j1 = 1;
    for (int i = 0; i < k; i++) {
        for (int j = 0; j < k; j++) {
            if (i != j) {
                set<int> help;
                for (int p = 0; p < cur[i].size(); p++) {
                    help.insert(cur[i][p]);
                }
                for (int p = 0; p < cur[j].size(); p++) {
                    help.insert(cur[j][p]);
                }
                if (cur[j].size() + cur[i].size() - help.size() > ans) {
                    ans = cur[j].size() + cur[i].size() - help.size();
                    i1 = i + 1;
                    j1 = j + 1;
                }
            }
        }
    }
    cout << ans << endl << i1 << ' ' << j1;
}
