#include<bits/stdc++.h>
using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
    cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args&&... args) {
    const char *comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#define pi 3.141592653589
#define MOD 1000000007
#define to() int tt; cin>>tt; while(tt--)
#define pb push_back
#define in insert
#define mp make_pair
#define ff first
#define ss second
#define si(s) s.size()
#define fori(it,v) for(it=v.begin();it!=v.end(); it++)
#define for1(i,low,high) for(int i=low;i<high;i++)
#define for2(i,low,high) for(int i=low;i<=high;i++)
#define rev(i,high,low)  for(int i=high;i>=low ;i--)
#define all(x) x.begin(), x.end()
#define fil(x,i) memset(x,i,sizeof(x));
#define setbits(x) __builtin_popcount(x)
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define read freopen("input.txt","r",stdin)
#define write freopen("output.txt","w",stdout)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
void i_o() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin) ;
    freopen("output.txt", "w", stdout) ;
#endif
}
int n,m,k;
vector<vector<int> >g;
vector<int>c;
vector<int>d[20];
int dp[1<<18][20];
void bfs(int i){
	d[i][c[i]]=0;
	queue<int>q;
	q.push(c[i]);
	while(!q.empty()){
		int cur=q.front(); q.pop();
		for(int j:g[cur]){
			if(d[i][j]>d[i][cur]+1){
				if(d[i][j]==1e7) q.push(j);
				d[i][j]=d[i][cur]+1;
			}
		}
	}
}

int fun(int mask,int i){
	if(mask==0|| mask==1<<i)
		return 0;
	if(dp[mask][i]!=-1) return dp[mask][i];
	int ans=1e7;
	if(i==k){
		for(int j=0;j<k;j++){
			ans=min(ans,fun(mask^(1<<j),j)+1);
		}
	}
	else
		for(int j=0;j<k;j++){
			if(!(mask&(1<<j))) continue;
			ans=min(ans,fun(mask^(1<<j),j)+d[j][c[i]]);
		}
	return dp[mask][i]=ans;
}

int main()
{
    boost; i_o();
    cin>>n>>m;
    g.resize(n+1);
    for1(i,0,m){
    	int a,b; cin>>a>>b;
    	g[a].pb(b); g[b].pb(a);
    }
    cin>>k;
	c.resize(k); 
	for1(i,0,k) d[i].resize(n+1,1e7);
    for1(i,0,k) cin>>c[i];
    for1(i,0,k) bfs(i);
  /*  for1(i,0,k){
    	cout<<"src= "<<c[i]<<endl;
    	for1(j,1,n+1) cout<<d[i][j]<<" ";
    	cout<<endl;
    }
    */
    fil(dp,-1);
 /*
    for1(mask,0,(1<<k)) for1(i,0,k+1) dp[mask][i]=1e7;
    for1(i,0,k) dp[1<<i][i]=d[0][i]=0;
    for(int mask=0;mask<(1<<k);mask++){
    	for(int i=0;i<k;i++){
    			if(!(mask&(1<<i))) continue;
    			for(int j=0;j<k;j++){
    				 if(!(mask&(i<<j))) continue;
    				dp[mask][i]=min(dp[mask][i],dp[mask^i][j]+d[c[j]][c[i]]);
    			}
    	}
    }
    */
    int ans=fun((1<<k)-1,k);
    if(ans>=1e7) ans=-1;
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;++i)
#define repn(i,n) for(int i=1;i<=n;++i)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

int n,m,c[110],depth[110],ans[10010];
vector <pair <pii,int> > g[110];
vector <pii> e;
bool vis[110];

void dfs(int pos,int par,int d)
{
	vis[pos]=true;
	depth[pos]=d;
	bool bk=false;
	rep(i,g[pos].size())
	{
		if(g[pos][i].fi.fi==par&& !bk)
		{
			bk=true;
			continue;
		}
		if(vis[g[pos][i].fi.fi])
		{
			if(depth[g[pos][i].fi.fi]<d) ans[g[pos][i].fi.se]=(g[pos][i].se==0 ? 1:2);
		}
		else
		{
			ans[g[pos][i].fi.se]=(g[pos][i].se==0 ? 1:2);
			dfs(g[pos][i].fi.fi,pos,d+1);
		}
	}
}

int main()
{
	cin>>n>>m;
	int x,y;
	rep(i,m)
	{
		scanf("%d%d",&x,&y);
		e.pb(mpr(x,y));
	}
	repn(i,n) scanf("%d",&c[i]);
	rep(i,m)
	{
		if(c[e[i].fi]>c[e[i].se]) ans[i]=1;//->
		else if(c[e[i].fi]<c[e[i].se]) ans[i]=2;//<-
		else
		{
			g[e[i].fi].pb(mpr(mpr(e[i].se,i),0));
			g[e[i].se].pb(mpr(mpr(e[i].fi,i),1));
		}
	}
	repn(i,n)
	{
		if(vis[i]) continue;
		dfs(i,0,1);
	}
	rep(i,m) puts(ans[i]==1 ? "->":"<-");
	return 0;
}