#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back
#define f first
#define s second
#define M 1000000007
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
const int N = 1e5 , inf = 1e9;
int n , m , k , c[17] , dist[17][N] , id[N] , dp[17][1<<17] , vis[N];
vector<int> g[N];
void bfs(int srce){
	memset(vis , 0 , sizeof vis);
	vis[srce] = 1;
	queue<int> q;
	q.push(srce);
	while(!q.empty()){
		int x = q.front();
		q.pop();
		for(auto u : g[x]){
			if(vis[u]) continue;
			vis[u] = 1;
			dist[id[srce]][u] = dist[id[srce]][x] + 1;
			q.push(u);
		}
	}
}
int main() {
	scanf("%d%d",&n,&m);
	for (int i = 0,u,v; i < m; ++i){
		scanf("%d%d",&u,&v);
		--u,--v;
		g[u].pb(v);
		g[v].pb(u);
	}
	scanf("%d",&k);
	for (int i = 0; i < k; ++i){
		scanf("%d", &c[i]);
		--c[i];
		id[c[i]] = i;
	}
	
	for (int i = 0; i < k; ++i){
		bfs(c[i]);
	}

	for (int j = 0; j < k; ++j){
		if(vis[c[j]] == 0) return puts("-1") , 0;
	}

	for (int i = 0; i < k; ++i){
		for (int j = 1; j < (1<<k); ++j){
			dp[i][j] = inf;
		}
	}

	vector<vector<int>> msk(k+1);
	for (int i = 0; i < (1 << k); ++i){
		msk[__builtin_popcount(i)].pb(i);
	}

	for (int i = 0; i < k; ++i) dp[i][1<<i] = 1;

	for (int i = 2; i <= k; ++i){
		for(auto mask : msk[i-1]){

			for (int j = 0; j < k; ++j){
				for (int o = 0; o < k; ++o){
					if(mask >> j & 1) continue;
					if(mask >> o & 1){
						dp[j][mask|(1<<j)] = min(dp[j][mask|(1<<j)] , dp[o][mask] + dist[o][c[j]]);
					}
				}
			}


		}
	}

	int ans = inf;
	for (int i = 0; i < k; ++i){
		ans = min(ans , dp[i][(1 << k) - 1]);
	}
	printf("%d\n", ans);
}
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>
#include <bitset>
#include <chrono>
#include <random>
#include <assert.h>
#include <array>

using namespace std;

template<typename M, typename N>
istream& operator>>(istream&is, pair<M,N> & p){is >> p.first >> p.second; return is;}
template<typename M>
istream& operator>>(istream&is, vector<M> & v){for(auto &it:v) is >> it; return is; }
template<typename M>
istream& operator>>(istream&is, vector<vector<M>> & v){for(auto &it:v) is >> it; return is; }
template<typename M, typename N>
ostream& operator<<(ostream&os, const pair<M,N> &p){os << p.first << ' ' << p.second << '\n';return os;}
template<typename M>
ostream& operator<<(ostream&os, const vector<M> &v){for(auto it: v)os << it << ' ';cout << '\n';return os;}
template<typename M>
ostream& operator<<(ostream&os, const vector<vector<M>> &v){for(auto it: v)os << it;return os;}

#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mn(x) *min_element((x).begin(),(x).end())
#define mx(x) *max_element((x).begin(),(x).end())
#define acc(x) accumulate((x).begin(),(x).end(),0ll)
#define unique(x) sort(all(x)); x.erase(unique(all(x)),x.end());
#define eb emplace_back
#define el '\n'
typedef  long long  ll;
typedef  unsigned long long  ull;
typedef long double ld;
typedef complex<long double> cd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vs;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const ld pi=acos(-1);
const ll inf=(ll)1e9+10;
const int mod=1000000007;
//const int mod=998244353;

int n, m, k;
const int N=1e2+10;

vvi g(N);
set<pii> ee;
vi mark(N);
void dfs(int node, int par){
    mark[node]=1;
    for(int child: g[node]){
        if(child!=par){
            if(!mark[child]){
                dfs(child, node);
                
            }
            if(ee.find({child,node})==ee.end())
                ee.insert({node,child});
        }
    }
};


int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n, m;
    cin >> n >> m;
    vpi e(m);
    for(int i=0; i<m; i++){
        cin >> e[i].fi >> e[i].se;
        e[i].fi--; e[i].se--;
    }
    vi c(n);
    cin >> c;
    vi todo(n);
    for(int i=0; i<m; i++){
        if(c[e[i].fi]==c[e[i].se]){
            todo[e[i].fi]=1;
            todo[e[i].se]=1;
            g[e[i].fi].pb(e[i].se);
            g[e[i].se].pb(e[i].fi);
        }
    }
    for(int i=0; i<n; i++){
        if(todo[i] && !mark[i]){
            dfs(i,i);
        }
    }
    for(int i=0; i<m; i++){
        if(c[e[i].fi]==c[e[i].se]){
            if(ee.find({e[i].fi,e[i].se})!=ee.end()){
//                cout << e[i].fi+1 << ' ' << e[i].se+1 << el;
                cout << "->\n";
            }
            else{
                assert(ee.find({e[i].se,e[i].fi})!=ee.end());
                cout << "<-\n";
            }
        }
        else if(c[e[i].fi]>c[e[i].se]){
            cout << "->\n";
        }
        else{
            cout << "<-\n";
        }
    }
    
    return 0;
}

