//@formatter:off
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define rrep(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = int(s); i < int(n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<P>
#define vvp vector<vector<P>>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?"":","); return os<<']'; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << '\n'; }
void YES(bool b) { cout << (b ? "YES" : "NO") << '\n'; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;
//@formatter:on

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vi w(n);
    cin >> w;
    sort(all(w));
    int mx = *max_element(all(w));
    vp cond;
    rep(_, m) {
        int l, v;
        cin >> l >> v;
        if (v < mx) {
            cout << -1 << endl;
            return 0;
        }
        cond.eb(v, l);
    }
    sort(all(cond));
    rep(i, m - 1) chmax(cond[i + 1].second, cond[i].second);
    int ans = inf;
    // 40320
    do {
        vi pos(n, 0);
        rep2(i, 1, n) {
            pos[i] = pos[i - 1];
            int sum = w[i];
            rrep(j, i) {
                sum += w[j];
                auto it = lower_bound(all(cond), make_pair(sum, 0));
                if (it == cond.begin()) continue;
                it--;
                int nd = it->second;
                chmax(pos[i], pos[j] + nd);
            }
        }
        chmin(ans, pos[n - 1]);
    } while (next_permutation(all(w)));
    assert(ans != inf);
    cout << ans << endl;
}
#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <tuple>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <functional>
#include <numeric>
#include <iomanip> 
#include <stdio.h>
//end of libraries
#define lnf 3999999999999999999
#define inf 999999999
#define PI 3.14159265359
#define endl "\n"
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c).size()
#define mkp(a,b) make_pair(a,b)
#define make_unique(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define rsz(a,n) a.resize(n)
#define pii pair <int,int>
#define tpii pair <int, pii>
#define rep(i,n) for(int i = 0 ; i < n ; i++) 
#define drep(i,n) for(int i = n-1 ; i >= 0 ; i--)
#define crep(i,x,n) for(int i = x ; i < n ; i++)
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);

const int max_n = 900155;

using namespace std;
int n , m , k;

int dp[max_n][30];

int p[max_n] , siz[max_n] , f[max_n];

int table[30][30];

vector <int> c , vc[max_n];

int getp(int x) { return p[x] == x ? x : getp(p[x]); }

void mku(int x, int y) {
	int A = getp(x) , B = getp(y);
	if(A == B) return;
	if(siz[A] > siz[B]) {
		siz[A] += siz[B];
		p[B] = A;
		return;
	}
	siz[B] += siz[A];
	p[A] = B;
}
 
int find(int x,int need){
	queue <pii> q;
	vector <int> usd;
	
	usd.resize(max_n,0);
	
	q.push({0,x});
 
	while(sz(q)) {
		pii point = q.front();
		
		int value = point.fi , hm = point.se;

		q.pop();
 
		usd[hm] = 1;
 
		for(auto &y : vc[hm]) {
			if(y == need) {
				return value + 1;
			}
			if(usd[y]==0) q.push({value + 1 , y});
		}
	
	}
}
 
 
int main(){
fcin;
	rep(i,max_n-4) p[i]=i,siz[i]=1;


	cin >> n >> m;
	
	rep(i,m){
		int u,v;
		cin >> u >> v;
		u--,v--;
		mku(u,v);
		vc[u].pb(v);
		vc[v].pb(u);
	}
	cin >> k;
	c.resize(k,0);
	rep(i,k) {
		cin >> c[i];
		c[i]--;
	}
	rep(i,k) {
		rep(j,k) {
			if(getp(c[i])!=getp(c[j])) {
				cout << "-1\n"; return 0;
			}
		}
	}
	rep(i,k) {
		rep(j,k) {
			if(i==j) continue;
			table[i][j] = find(c[i],c[j]);
		}
	}
	int mxmxmx = pow(2,k);
	rep(msk,mxmxmx) {
		rep(i,k) dp[msk][i] = inf;
	}
	
	rep(i,k) {
		dp[(1<<i)][i] = 1;
	}

	rep(msk,mxmxmx) {
		
		rep(i,k) {

			if(msk&(1<<i)) continue;
			
			rep(f,k) {
				
				if(i==f or dp[msk][f] == inf) continue;
				
				int nx = msk|(1<<i);

				dp[nx][i] = min(dp[nx][i] ,
					dp[msk][f] + table[i][f]
				 );
	
			}
		}	
	}
	int ans = inf;

	rep(i,k) {
		ans = min(ans,dp[mxmxmx-1][i]);
	}
	cout << ans << '\n';

/*
*/
	return 0;	
}