#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PI acos(-1)
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
const int MOD = 1e9+ 7;
const int INF = numeric_limits<int>::max() - (int)1e8;
const ll INFLL = numeric_limits<ll>::max() - (ll)1e17;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> G(N);
    for (int i = 0; i < N; i++) {
        G[i] = (1<<i);
    }
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a] |= (1<<b);
        G[b] |= (1<<a);
    }

    vector<bool> is_complete(1<<N);
    for (int i = 0; i < (1<<N); i++) {
        bool check = true;
        for (int j = 0; j < N; j++) {
            if (((i>>j)&1) == 0) {
                continue;
            }
            if ((G[j]&i) != i) {
                check = false;
            }
        }
        is_complete[i] = check;
    }

    vector<int> dp(1<<N, INF);
    dp[0] = 0;
    for (int i = 0; i < (1<<N); i++) {
        int other = (1<<N) - 1 - i;
        for (int sub = other; ; sub = (sub - 1) & other) {
            if (sub == 0) {
                break;
            }

            if (is_complete[sub]) dp[i | sub] = min(dp[i | sub], dp[i] + 1);
        }
    }
    cout << dp[(1<<N) - 1] << endl;
}

#include <bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
#define me0(a) memset(a,0,sizeof(a))
#define me1(a) memset(a,-1,sizeof(a))
#define op freopen("in.txt", "r", stdin)
#define op1 freopen("C:\\acm\\Cproj\\in.txt","r",stdin);
#define pr freopen("C:\\acm\\Cproj\\out.txt","w",stdout)
#define pr2 freopen("C:\\acm\\Cproj\\std.txt","w",stdout)
#define pii pair<int,int>
#define Please return
#define AC 0
using namespace std;
const int INF = 0x3f3f3f3f;
typedef long long LL;
template <class T>
void read(T &val) { T x = 0; T bz = 1; char c; for (c = getchar(); (c<'0' || c>'9') && c != '-'; c = getchar()); if (c == '-') { bz = -1; c = getchar(); }for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48; val = x * bz; }
const int mod=998244353;
const int maxn = 1e6+10;

int n,m,a[maxn],q,t,k;
bool vis[maxn];
int pos[maxn];

int main(){
    read(n);
    fo(i,1,n) read(a[i]),pos[a[i]]=i;
    vector<int>ans;
    fod(i,n,1){
        if(pos[i]!=i){
            while(pos[i]!=i){
                if(vis[pos[i]]) {
                    puts("-1");return 0;
                }
                vis[pos[i]] = 1;
                ans.push_back(pos[i]);
                int p = pos[i];
                swap(a[p],a[p+1]);
                pos[a[p]] = p;pos[a[p+1]] = p+1;
            }

        }
    }

    if(ans.size()!=n-1){
        puts("-1");return 0;
    }

    for(auto to:ans) printf("%d\n",to);


    Please AC;
}