#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ll;
const int MOD = 1000000007;

void solve(){
	int n,m;
	cin>>n>>m;
	int **arr = new int*[n];
	int s = INT_MAX;
	for(int i=0;i<n;i++){
		arr[i] = new int[m]();
		for(int j=0;j<m;j++){
			cin>>arr[i][j];
			s = min(s,arr[i][j]);
		}
	}
	int ans = 0;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			ans = ans + (abs(arr[i][j]-s));
		}
	}
	cout<<ans<<endl;
	return;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sys/types.h>
#include <unistd.h>
#include <vector>

#pragma region macros
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) _range(i, 0, n)
#define _range(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(...) _overload(__VA_ARGS__, _range, _rep, )(__VA_ARGS__)
#define _rrep(i, n) _rrange(i, n, 0)
#define _rrange(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)
#define rrep(...) _overload(__VA_ARGS__, _rrange, _rrep, )(__VA_ARGS__)
#pragma endregion macros

using namespace std;

template <class T> bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T> bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

using ll    = long long;
using R     = long double;
const R EPS = 1e-9L;  // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R &r) {
    return (r > EPS) - (r < -EPS);
}
inline R sq(R x) {
    return sqrt(max(x, 0.0L));
}

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

const pid_t pid = getpid();
// Problem Specific Parameter:

using edge = struct { int to; };
using G    = vector<vector<edge>>;

vector<int> bfs(const G &graph, int s, int inf) {
    const int n = graph.size();
    vector<int> dist(n, inf);

    queue<int> q;
    dist[s] = 0, q.push(s);

    while (!q.empty()) {
        int v = q.front();
        q.pop();
        for (auto &e: graph[v]) {
            int nc = dist[v] + 1, nv = e.to;
            if (chmin(dist[nv], nc))
                q.push(nv);
        }
    }
    return dist;
}
int dp[1 << 17][17];

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

    G graph(n);

    rep(i, m) {
        int a, b;
        cin >> a >> b;
        graph[a - 1].push_back({b - 1});
        graph[b - 1].push_back({a - 1});
    }

    int k;
    cin >> k;
    vector<int> c(k);
    rep(i, k) {
        cin >> c[i];
        c[i]--;
    }

    const int inf = 1 << 25;
    int cost[20][20];

    rep(i, k) {
        const int src    = c[i];
        vector<int> dist = bfs(graph, src, inf);
        rep(j, k) {
            cost[i][j] = dist[c[j]];
        }
    }

    rep(mask, 1 << k) rep(i, k) {
        dp[mask][i] = inf;
    }

    rep(i, k) {
        dp[1 << i][i] = 0;
    }

    rep(mask, 1 << k) rep(i, k) {
        if ((mask >> i) & 1) {
            rep(j, k) {
                if ((mask >> j) & 1) {
                    continue;
                }
                const int nmask = mask | (1 << j);
                chmin(dp[nmask][j], dp[mask][i] + cost[i][j]);
            }
        }
    }

    int ans = inf;
    rep(i, k) {
        chmin(ans, dp[(1 << k) - 1][i] + 1);
    }

    if (ans == inf) {
        ans = -1;
    }

    cout << ans << endl;

    return 0;
}