#include <iostream>
#include <iomanip>
#include <cstdio>
 
#include <cassert>
#include <cmath>
#include <algorithm>
#include <utility>
 
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <bitset>
 
using std::cin;
using std::cout;
using std::cerr;
 
using std::max;
using std::min;
using std::abs;
 
using std::vector;
using std::set;
using std::map;
using std::pair;
using std::bitset;
 
#define ff first 
#define ss second
#define pb push_back
#define print(x) cerr << (x) << '\n'
#define dbg(a) cerr << #a << " = " << (a) << '\n'
#define dbg2(a, b) cerr << #a << " = " << (a) << " " << #b << " = " << (b) << '\n'
#define dbg3(a, b, c) cerr << #a << " = " << (a) << " " << #b << " = " << (b) << " " << #c << " = " << (c) << '\n'
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
void init() {
    #ifndef LOCAL
    freopen("twopaths.in", "r", stdin);
    freopen("twopaths.out", "w", stdout);
    #endif
    std::iostream::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(10);
    cerr << std::fixed << std::setprecision(10);
}
 
const int MAXN = 1e5 + 1, MAXK = 1e3 + 1, MAXB = 16;
bool used[MAXN];
uint arr[MAXK][MAXN / MAXB + 5];
vector<pii> graph[MAXN];
int target;
bool dfs(int v, int c) {
    used[v] = true;
    if (v == target) {
        return true;
    }
    for (auto e : graph[v]) {
        int to = e.ff, num = e.ss;
        if (!used[to]) {
            if (dfs(to, c)) {
            	int block = num / MAXB, bit = num % MAXB;
                arr[c][block] |= (1u << bit);
                return true;
            }
        }
    }
    return false;
}
int cntbits[(1 << MAXB) + 1];
void precalc() {
	for (int i = 0; i < (1 << MAXB); ++i)
		cntbits[i] = __builtin_popcount(i);
}
void tlassert(bool a) {
	if (!a) {
		while (true);
	}
}

int rs[MAXK];

int main() {
    init();
 	precalc();


    int n, k;
    cin >> n >> k;
    for (int i = 2; i <= n; ++i) {
        int x;
        cin >> x;
        graph[x].pb({i, i - 1});
        graph[i].pb({x, i - 1});
    }
 
    for (int t = 1; t <= k; ++t) {
        int a, b;
        cin >> a >> b;
        for (int i = 1; i <= n; ++i)
            used[i] = false;
        target = b;
        dfs(a, t);
        rs[t] = t;
    }

    std::random_shuffle(rs + 1, rs + k + 1);

    int mx = -1, mxa, mxb;
    for (int x = 1; x <= k; ++x) {
    	int i = rs[x];
    	int w = 0;
        for (int j = 0; j <= n / MAXB; ++j) {
    		uint tmp = arr[i][j];
    		w += cntbits[tmp];
        }
        if (w <= mx)
            continue;
        for (int y = x + 1; y <= k; ++y) {
        	int j = rs[y];
        	int cnt = 0;
        	for (int q = 0; q <= n / MAXB; ++q) {
        		uint tmp = arr[i][q] & arr[j][q];
        		cnt += cntbits[tmp];
        	}
            if (mx < cnt) {
                mx = cnt;
                mxa = i, mxb = j;
            }
        }
    }
 
    cout << mx << '\n' << mxa << ' ' << mxb << '\n';
 
 
    return 0;
}