#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;
bool used[MAXN];
uint arr[MAXK][MAXN / 32 + 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 / 32, bit = num % 32;
                arr[c][block] |= (1u << bit);
                return true;
            }
        }
    }
    return false;
}
int cntbits[(1 << 16) + 1];
void precalc() {
	for (int i = 0; i < (1 << 16); ++i)
		cntbits[i] = __builtin_popcount(i);
}
uint tmp[MAXN / 32 + 1];
int popcount(int n) {
	int res = 0;
	for (int i = 0; i <= n / 32; ++i)
	{
		uint big = tmp[i] >> 16;
		uint small = tmp[i] - big;
		res += cntbits[big] + cntbits[small];
	}
	return res;
}

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);
    }

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