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

#define all(v) (v).begin(),(v).end()
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi=vector<vi>;

constexpr int inf=1e9+7;
constexpr ll longinf=1LL<<60 ;
constexpr ll mod=1e9+7 ;

int main(){
  int n,m;
  cin>>n>>m;
  vi a(m),b(m);
  vvi g(n);
  rep(i,m){
    cin>>a[i]>>b[i];
    a[i]--;b[i]--;
    g[a[i]].push_back(b[i]);
    g[b[i]].push_back(a[i]);
  }
  int K;cin>>K;
  vi c(K);
  rep(i,K){
    cin>>c[i];
    c[i]--;
  }
  //cout<<1;
  vvi dist(K,vi(n,inf));
  rep(i,K){
    queue<int>q;
    q.push(c[i]);
    dist[i][c[i]]=0;
    while(q.size()){
      int u=q.front();q.pop();
      for(auto v:g[u]){
        if(dist[i][v]>dist[i][u]+1){
          dist[i][v]=dist[i][u]+1;
          q.push(v);
        }
      }
    }
  }
  //cout<<dist[0][1];
  vvi dp(1<<K,vi(K,inf));
  rep(i,1<<K){
    int cnt=0,memo=-1;
    rep(j,K){
      if(i & (1<<j)){
        cnt++;
        memo=j;
      }
    }
    if(cnt==1)dp[i][memo]=1;
    rep(t,K){
      rep(j,K){
        dp[i|(1<<j)][t]=min(dp[i|(1<<j)][t], dp[i][j]+dist[j][c[t]]);
      }
    }
  }
  int ans=inf;
  rep(i,K){
    ans=min(ans,dp[(1<<K)-1][i]);
  }
  if(ans==inf)cout<<-1;
  else cout<<ans;
}
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define bit(n,k) ((n>>k)&1) //nのk　bit目
using ll = long long;
using P = pair<int,int>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll llINF = 1LL << 60;
const int iINF = 1e9;

//---main---------------------------------------------
int main(){
    //main
    int A,B;
    cin >> A >> B;

    int sa=0,sb=0;
    rep(i,3){
        sa += A%10;
        A /=10;
        sb += B%10;
        B /= 10;
    }

    if(sa>=sb) cout << sa << endl;
    else cout << sb << endl;

    return 0;
}