#include <bits/stdc++.h>
using namespace std;
#define int long long
using vec_int = vector<int>;
using P = pair<int,int>;
using T = tuple<int,int,int>;
using Q = tuple<int,int,int, int, int>;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}
int solve(vector<vec_int> &DP, vector<vec_int> &mat, int state, int pos, int K){
    if(DP.at(state).at(pos)>=0){
        return DP.at(state).at(pos);
    }
    int temp=1;
    vec_int city_vec;
    rep(i,K){
        if((state/temp)%2==1 && i!=pos){
            city_vec.push_back(i);
        }
        temp*=2;
    }
    if(city_vec.size()==0){
        DP.at(state).at(pos) = 1;
        return 1;
    }

    int next_state = state - (1<<pos);

    int result = INT_MAX; 
    for(auto next_city: city_vec){
        int temp = solve(DP, mat, next_state, next_city, K) + mat.at(next_city).at(pos);
        result = min(temp, result);
    }
    DP.at(state).at(pos) = result;
    return result;
}
signed main(){
    int N, M; cin>>N>>M;
    vec_int A(M), B(M); rep(i,M)cin>>A.at(i)>>B.at(i);
    vector<vec_int> G(N+1);
    rep(i,M){
        G.at(A.at(i)).push_back(B.at(i));
        G.at(B.at(i)).push_back(A.at(i));
    }

    int K; cin>>K;
    vec_int C(K); rep(i,K)cin>>C.at(i);
    vector<vec_int> mat(K, vec_int(K,-1));

    rep(k,K){
        int start = C.at(k);
        priority_queue<P, vector<P>, greater<P>> pq;
        pq.emplace(0, start);
        vec_int visited(N+1, -1);
        while(!pq.empty()){
            int cost, pos; tie(cost, pos) = pq.top(); pq.pop();
            if(visited.at(pos)>=0)continue;
            visited.at(pos) = cost;
            for(auto next_pos: G.at(pos)){
                if(visited.at(next_pos)>=0)continue;
                pq.emplace(cost+1, next_pos);
            }
        }
        rep(i,K){
            mat.at(k).at(i) = visited.at(C.at(i)); //都市kからiまでの最短コスト, -1の時には到達不能
            if(visited.at(C.at(i))==-1){
                cout<<-1<<endl;
                return 0;
            }
        }
    }

    // TSPをbitDPで解く
    // DP.at(i).at(j): 今までの回った年: i, 最後の都市i
    vector<vec_int> DP(1<<K, vec_int(K, -1));
    int ans = INT_MAX;
    rep(i,K){
        ans = min(ans, solve(DP, mat, (1<<K)-1, i, K));
    }
    cout<<ans<<endl;


    return 0;
}
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()

int main() {
    int n,ans,cnt=0;
    cin>>n;
    string s;
    cin>>s;
    if(s[0]!=s[n-1])ans=1;
    else{
        char x=s[0];
        rep(i,n-1){
            if(s[i]!=x&&s[i+1]!=x)cnt++;
        }
        if(cnt)ans=2;
        else ans = -1;
    }
    cout<<ans;
    
	return 0;
}
