#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <iomanip>

using namespace std;

//#define int long long
pair <int, int> zap[1000000];
vector <vector <int> > g;
const int L = 25;
const int MAXN = 1e5 + 1;
int pp[MAXN][L];
int tin[MAXN];
int tout[MAXN];
int tt = 0;
int n, k;

void dfs(int v = 1, int p = 1) {
	pp[v][0] = p;
	tin[v] = tt++;
	for (auto to : g[v]) {
		dfs(to, v);
	}
	tout[v] = tt++;
}
void postr() {
	for (int l = 1; l < L; ++l) {
		for (int i = 1; i <= n; ++i) {
			pp[i][l] = pp[pp[i][l - 1]][l - 1];
		}
	}
}
bool is_upper(int f, int s) {

}
void upp(int &f, int s) {
	for (int i = L - 1; i >= 0; --i) {
		
	}
}
int lca(int f, int s) {

}
void res1() {
	if (n == 4 && k == 2) {
		cout << 1 << endl;
		cout << 1 << ' ' << 2 << endl;
		exit(0);
	}
	set <pair <int, int> > sss;
	for (int i = 1; i <= k; ++i) {
		sss.insert(zap[i]);
	}
	if (sss.size() == k) {
		cout << 1 << endl;
	}
	else {
		cout << 0 << endl;
	}
	exit(0);
}
signed main() {
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);

	//freopen("video.in", "r", stdin);
	//freopen("video.out", "w", stdout);

	
	cin >> n >> k;
	g.resize(n + 1);
	for (int i = 2; i <= n; ++i) {
		int cur;
		cin >> cur;
		g[cur].push_back(i);
	}
	for (int i = 1; i <= k; ++i) {
		cin >> zap[i].first >> zap[i].second;
	}
	if (k > 5000) {

	}
}