#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for (int i = k; i < (int)(n); i++)
#define repd(i, n) for (int i = n-1; i >= 0; i--)
#define rrepd(i, k, n) for (int i = n-1; i >= (int)(k); i--)
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
//V,Pは大文字i,l,bは小文字
using ll = long long;
using Vi = vector<int>;
using VVi = vector<Vi>;
using Vl = vector<ll>;
using VVl = vector<Vl>;
using Vb = vector<bool>;
using VVb = vector<Vb>;
using P = pair<int,int>;
using Pl = pair<ll, ll>;
using Vs = vector<string>;
const ll mod = 1000000007;
const ll inf = 1000000000000000000;//10の18乗
#define yn {puts("Yes");}else{puts("No");}
#define dame { puts("-1"); return 0;}

int main() {
    ll n;
    cin >> n;
    Vl v(n);
    rep(i,n) cin >> v[i];
    ll now=0;//操作回数
    Vl whe(n);
    rep(i,n) whe[v[i]-1]=i;
    Vl ans;//あとでインクリメント
    Vl used(n-1,0);
    rep(i,n-1){
        ll x=whe[i];
        if(x<=i) continue;
        //ll y=x-i;
        for(int j=x-1;j>=i;j--){
            ans.PB(j);
            if(used[j])dame;
            used[j]++;
            now++;
            //cout << j << endl;
            swap(v[j],v[j+1]);
            whe[v[j]-1]=j;
            whe[v[j+1]-1]=j+1;
            //cout <<j<< endl;
        }

    }
    if(now!=n-1) dame;
    rep(i,n-1) cout << ans[i]+1 << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template <typename T>
void update_max(T& a, T b) {
    if (b > a) a = b;
}
template <typename T>
void update_min(T& a, T b) {
    if (b < a) a = b;
}
int main() {
#ifdef LOCAL_PROJECT
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M;
    ll INF = 100000000000;
    cin >> N >> M;
    vector<vector<int>> graph(N);
    rep(i, 0, M) {
        int A, B;
        cin >> A >> B;
        A--;
        B--;
        graph[A].push_back(B);
        graph[B].push_back(A);
    }
    int K;
    cin >> K;
    vector<vector<ll>> dist(K, vector<ll>(K, INF));
    vector<int> C(K);
    unordered_map<int, int> C_map;
    rep(i, 0, K) {
        cin >> C[i];
        C[i]--;
        C_map[C[i]] = i;
    }
    rep(i, 0, K) { dist[i][i] = 0; }
    rep(i, 0, K) {
        // BFS
        queue<pair<int, int>> Q;  // {index, depth}
        vector<bool> visited(N, false);
        Q.push({C[i], 0});
        visited[C[i]] = true;
        while (!Q.empty()) {
            pair<int, long long> node = Q.front();
            Q.pop();
            for (int child : graph[node.first]) {
                if (!visited[child]) {
                    if (C_map.count(child) > 0) {
                        dist[C_map[C[i]]][C_map[child]] = min(
                            dist[C_map[C[i]]][C_map[child]], node.second + 1);
                    }
                    visited[child] = true;
                    Q.push({child, node.second + 1});
                }
            }
        }
    }
    rep(i, 0, K) {
        rep(j, 0, K) {
            if (dist[i][j] == INF) {
                cout << -1;
                return 0;
            }
        }
    }
    vector<vector<ll>> dp(K, vector<ll>(1 << K, INF));
    rep(i, 0, K) { dp[i][1 << i] = 0; }
    rep(mask, 0, 1 << K) {
        rep(i, 0, K) {
            if ((mask & (1 << i)) != 0) {
                rep(j, 0, K) {
                    if (i != j && (mask & (1 << j)) != 0) {
                        // dp[j][mask ^ (1 << i)] != INF &&
                        // dp[j][mask ^ (1 << i)] + dist[i][j] < dp[i][mask]

                        dp[i][mask] =
                            min(dp[i][mask],
                                min(dp[j][mask ^ (1 << i)] + dist[i][j],
                                    dp[j][mask] + dist[i][j]));
                    }
                }
            }
        }
    }
    ll answer = INF;
    rep(i, 0, K) { answer = min(answer, dp[i][(1 << K) - 1]); }
    cout << answer + 1;
    return 0;
}