#include<bits/stdc++.h>
using namespace std;
#define     M                     1000000007
#define     ll                    long long
#define     FIO                   ios_base::sync_with_stdio(false);cin.tie(NULL)
#define     ifor(st,lim)          for(int i=st;i<lim;i++)
#define     jfor(stt,llim)        for(int j=stt;j<llim;j++)
#define     pb                    push_back

vector<int> adj[2005];
int vis[2005];
int ans;
void dfs(int node) {
	vis[node] = 1;

	for(auto child : adj[node]) {
		if(!vis[child]) {
			ans++;
			dfs(child);
		}
	}
}

void solve() {
	int n,m; cin>>n>>m;

	while(m--) {
		int a,b; cin>>a>>b;
		adj[a].pb(b);
	}
	ans = n;
	for(int i=1;i<=n;i++) {
		memset(&vis,0,sizeof vis);
		if(!vis[i]) 
			dfs(i);
	}
	cout<<ans;
}
void file_i_o() {
	#ifndef ONLINE_JUDGE  
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
}
int main()
{
	file_i_o();
	FIO;
	int t=1;
	while(t--) {
		solve();
	}
}	
#include <bits/stdc++.h>
using namespace std;
#define deb(k) cerr << #k << ": " << k << "\n";
#define size(a) (int)a.size()
#define fastcin cin.tie(0)->sync_with_stdio(0);
#define st first
#define nd second
#define pb push_back
#define mk make_pair
#define int long long
typedef long double ldbl;
typedef double dbl;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef vector<int> vint;
#define MAXN 300100
#define MAXLG 20
const int inf = 0x3f3f3f3f;
const ll mod = 1000000007;
const ll linf = 0x3f3f3f3f3f3f3f3f;
const int N = 200010;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

vector<pii>g[N];
int c[N];
int color[N];
pii ans[N];

void dfs(int x, int p = -1){
	color[x] = 1;
	for(pii e : g[x]){
		int v = e.st, i = e.nd;
		if(v == p) continue;
		if(!color[v]){
			ans[i] = {x, v};
			dfs(v, x);
		}
		else if(color[v] == 1){
			ans[i] = {x, v};
		}
	}
	color[x] = 2;
}

void solve(){
	int n, m;
	cin>>n>>m;
	vector<pii>e(m);
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		e[i] = {a, b};
	}
	for(int i=1;i<=n;i++) cin>>c[i];
	for(int i=0;i<m;i++){
		int a = e[i].st, b = e[i].nd;
		if(c[a] == c[b]){
			g[a].pb({b, i});
			g[b].pb({a, i});
		}
		else{
			if(c[a] < c[b]) ans[i] = pii(b, a);
			else ans[i] = pii(a, b);
		}
	}
	for(int i=1;i<=n;i++){
		if(!color[i]) dfs(i);
	}
	for(int i=0;i<m;i++){
		if(e[i].st == ans[i].st) cout<<"->\n";
		else cout<<"<-\n";
	}




	// Have you read the problem again?
	// Maybe you understood the wrong problem
}

int32_t main(){
	fastcin;
	int t_ = 1;
	//cin>>t_;
	while(t_--)
		solve();
	return 0;
}
