#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef	long long ll;
typedef long double ld;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef set<int> si;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define fi first
#define se second
#define pi 3.141592653589793
#define mod 998244353
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define pqmax priority_queue<int>
#define pqmin priority_queue<int,vi,greater<int>>
#define fio ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc int tt;cin>>tt;for(int ti=1;ti<=tt;ti++)
#define case_g "Case #"<<ti<<": "
#define RED "\033[31m"
#define GREEN "\033[32m"
#define RESET "\033[0m"
#define sleep for (int i = 1, a;i < 100000000;i++, a = a * a)
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> ranked_pairset;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ranked_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ranked_map;

const int N = 2001;

vi adj[N];
vb vis;
int ans = 0;

void dfs(int u) {
	vis[u] = 1;
	ans++;
	for (auto v : adj[u])
		if (!vis[v])
			dfs(v);
}


int main() {
	fio;
	int n, m;
	cin >> n >> m;
	for (int i = 0;i < m;i++) {
		int u, v;
		cin >> u >> v;
		adj[u].pb(v);
	}
	for (int i = 1;i <= n;i++) {
		vis.assign(n + 1, 0);
		dfs(i);
	}
	cout << ans << '\n';
}

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

const int inf = 1000000009;
const int maxn = 100005;
const int maxk = 17;

vector <int> g_init[maxn];
vector <pair <int, int> > g[maxk];
int d[maxk][1 << maxk];

int32_t main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; ++i) {
		int u, v;
		cin >> u >> v;
		g_init[u].push_back(v);
		g_init[v].push_back(u);
	}
	int k;
	cin >> k;
	vector <int> c(k);
	for (int i = 0; i < k; ++i) 
		cin >> c[i];
	bool can = 1;
	for (int j = 0; j < k; ++j) {
		int root = c[j];
		vector <int> dist(n + 1, inf);
		queue <int> q;
		dist[root] = 0;
		q.push(root);
		while (!q.empty()) {
			int u = q.front();
			q.pop();
			for (int v: g_init[u]) {
				if (dist[v] == inf) {
					dist[v] = dist[u] + 1;
					q.push(v);
				}
			}
		}
		for (int i = 0; i < k; ++i) {
			if (dist[c[i]] == inf)
				can = 0;
			else if (i != j)
				g[j].push_back(make_pair(i, dist[c[i]]));
		}
	}
	if (!can) {
		cout << "-1\n";
		return 0;
	}
	set <pair <int, pair <int, int> > > dset;
	for (int i = 0; i < k; ++i) {
		for (int mask = 0; mask < (1 << k); ++mask)
			d[i][mask] = inf;
		d[i][1 << i] = 1;
		dset.insert(make_pair(d[i][1 << i], make_pair(i, (1 << i))));
	}
	while (!dset.empty()) {
		pair <int, int> u = dset.begin() -> second;
		dset.erase(dset.begin());
		for (pair <int, int> e: g[u.first]) {
			int v = e.first, w = e.second;
			if (d[v][u.second | (1 << v)] > d[u.first][u.second] + w) {
				dset.erase(make_pair(d[v][u.second | (1 << v)], make_pair(v, (u.second | (1 << v)))));
				d[v][u.second | (1 << v)] = d[u.first][u.second] + w;
				dset.insert(make_pair(d[v][u.second | (1 << v)], make_pair(v, (u.second | (1 << v)))));
			}
		}
	}
	int ans = inf;
	for (int i = 0; i < k; ++i)
		ans = min(ans, d[i][(1 << k) - 1]);
	cout << ans << '\n';
}
