#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0, length = n; i < length; i++)
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ep emplace
#define epb emplace_back
#define scll static_cast<long long> 
#define sz(x) static_cast<int>((x).size())
#define pfll(x) printf("%lld\n", x)
#define ci(x) cin >> x
#define ci2(x, y) cin >> x >> y
#define ci3(x, y, z) cin >> x >> y >> z
#define ci4(w, x, y, z) cin >> w >> x >> y >> z
#define co(x) cout << x << endl
#define co2(x, y) cout << x << " " << y << endl
#define co3(x, y, z) cout << x << " " << y << " " << z << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> PQ;
typedef priority_queue<int, vector<int>, greater<int>> PQG;
typedef priority_queue<P> PQP;
typedef priority_queue<P, vector<P>, greater<P>> PQPG;

const int MAX_N = 100, MOD = 1e9 + 7, INF = 1e9;
int n, m, a[4950], b[4950], c[100];
bool ans[4950], used[4950];
vector<P> to[100];

void dfs(int x) {
    for (auto &i: to[x]) {
        if (used[i.se]) continue;
        if (i.fi == a[i.se]) ans[i.se] = 1;
        used[i.se] = true;
        dfs(i.fi);
    }
}

int main() {
    ci2(n, m);
    rep(i, m) ci2(a[i], b[i]);
    rep(i, n) ci(c[i]);
    rep(i, m) {
        a[i]--; b[i]--;
        if (c[a[i]] < c[b[i]]) ans[i] = 1;
        if (c[a[i]] == c[b[i]]) {
            to[a[i]].epb(b[i], i);
            to[b[i]].epb(a[i], i);
        }
    }
    rep(i, n) dfs(i);
    rep(i, m) {
        if (ans[i]) co("<-");
        else co("->");
    }
    return 0;
}

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define INF LONG_MAX/3
//#define DIV 1000000007
//#define DIV 998244353

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

vector<ll> to[100005];

//先手取り、後てとり、turn?
tuple<ll, ll, bool> dfs(ll pos) {
	//ここに来て撮った
	ll mypoint = 0;
	ll tekipoint = 1;
	bool myturn = true;

	//P0 - P1, P0, P1
	vector<tuple<ll, ll, ll> >V;
	ll sump0 = 0;
	ll sump1 = 0;
	for(ll next: to[pos]) {
		ll p0, p1;
		bool turn;
		tie(p0, p1, turn) = dfs(next);

		if(!turn) {
			//順番は変わらず的よりたくさん取れる
			if(p0 > p1) {
				mypoint += p0;
				tekipoint += p1;
			} else {
				//turnは変更せず、敵が徳、なるべく行きたくない
				sump0 += p0;
				sump1 += p1;
			}
		} else {
			V.push_back({p0 - p1, p0, p1});
		}
	}
	sort(V.rbegin(), V.rend());

	rep(i, V.size()) {
		ll _, p0, p1;
		tie(_, p0, p1) = V[i];
		if(myturn) {
			mypoint += p0;
			tekipoint += p1;
		} else {
			mypoint += p1;
			tekipoint += p0;
		}
		myturn = !myturn;
	}
	if(myturn) {
		mypoint += sump0;
		tekipoint += sump1;
		return {mypoint, tekipoint, true};
	} else {
		mypoint += sump1;
		tekipoint += sump0;
		return {mypoint, tekipoint, false};
	}
}

int main(){
	ll N;
	cin >> N;
	rep(i, N-1) {
		ll n;
		cin >> n;
		n--;
		to[n].push_back(i+1);
	}
	ll a, b, c;
	tie(a, b, c) = dfs(0);
	cout << b << endl;
}

