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

using ll = long long;
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define POPCOUNT(x) __builtin_popcount(x)
template <typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template <typename T> void chmax(T &a, const T &b) { a = max(a, b); }

const ll INF = 1LL << 60;

struct FastIO {
    FastIO() {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }
} fastiofastio;

const ll MOD = 1e9 + 7;

vector<int> G[100000];
ll dist[100000];
ll cost[17][17];
ll dp[1 << 17][17];

int main() {
    int N, M;
    cin >> N >> M;
    REP(i, M) {
        int A, B;
        cin >> A >> B;
        A--;
        B--;
        G[A].push_back(B);
        G[B].push_back(A);
    }
    int K;
    cin >> K;
    vector<int> C(K);
    REP(i, K) {
        cin >> C[i];
        C[i]--;
    }
    REP(i, K) {
        fill(dist, dist + N, INF);
        dist[C[i]] = 0;
        queue<int> que;
        que.push(C[i]);
        while (!que.empty()) {
            int now = que.front();
            que.pop();
            for (int to : G[now]) {
                if (dist[to] == INF) {
                    dist[to] = dist[now] + 1;
                    que.push(to);
                }
            }
        }
        FOR(j, i + 1, K) { cost[i][j] = cost[j][i] = dist[C[j]]; }
    }
    fill((ll *)dp, (ll *)(dp + (1 << K)), INF);
    REP(i, K) dp[1 << i][i] = 1;
    for (int bit = 1; bit < (1 << K); bit++) {
        REP(i, K) {
            if ((bit & (1 << i)) == 0)
                continue;
            REP(j, K) {
                if (bit & (1 << j))
                    continue;
                chmin(dp[bit ^ (1 << j)][j], dp[bit][i] + cost[i][j]);
            }
        }
    }
    ll ans = INF;
    REP(i, K) chmin(ans, dp[(1 << K) - 1][i]);
    if (ans == INF)
        cout << -1 << endl;
    else
        cout << ans << endl;
}
/*  Author: Tarun Kumar
    E-mail: tarunkumar281200@gmail.com

    " A code is like love,
        it has created with clear intentions at the beginning,
            but it can get complicated:) "
*/#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define test ll t;cin>>t;while(t--)
#define ll long long int
#define vll vector<ll>
#define ff first
#define ss second
#define pb push_back
#define f0(i,n) for(i=0;i<n;i++)
#define f1(i,n) for(i=1;i<=n;i++)
#define fab(i,a,b) for(i=a;i<=b;i++)
#define fabr(i,a,b) for(i=b;i>=a;i--)
#define memo(a,b) memset(a,b,sizeof(a))
#define display(x) for(auto dsp:x)cout<<dsp<<" ";cout<<"\n";
#define hi cout<<"hi\n"
#define ln "\n"
using namespace std;
int main()
{FAST;ll n,i,j,k,len,x,y,z,c,f,flag,p,q,mx,mn,l,r,sum,ans,tmp,it,pos,avg,m,cnt;
    // test
    {
        f=0;flag=0;ans=0;cnt=0;sum=0;mn=LLONG_MAX;mx=LLONG_MIN;string s;
        cin>>n;
        
        vll v;
        ll a[n],b[n];
        f0(i,n)
        {
            cin>>a[i];
            b[i]=a[i];
            if(a[i]==i+1) f=1;
        }
        sort(b,b+n);
        
        if(f)
        {
            cout<<-1;
            return 0;
        }
        
        bitset<1000000>bt;
        f0(i,n-1)
        {
            if(bt[i])
            {
                continue;
            }
            else
            {
                pos=i+1;
                while(pos<n&&a[pos]!=b[i]) pos++;
                
                // cout<<pos<<" ";
                if(pos>=n||i+1>=n) goto lbl;
                
                fabr(j,i+1,pos)
                {
                    if(bt[j-1]) goto lbl;
                    
                    swap(a[j],a[j-1]);
                    bt[j-1]=1;
                    v.pb(j);//+1
                }
                // i=pos;
                // if(bt[])
            }
        }
        lbl:
        
        if(is_sorted(a,a+n))
        {
            for(auto it:v) cout<<it<<ln;
        }
        else cout<<-1;
    }
	return 0;
}