#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007;
constexpr long long INF = 1000000000 + 100;
constexpr long long LINF = 1000000000000000000 + 100;
#define all(v) v.begin(), v.end()
#define rep(i, n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
#define rrep(i, n) for(int i=(n); i>=0; i--)
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; }


int main(){
    ll N, M; cin >> N >> M;
    vector<pll> pawn(M);
    rep(i, M){
        ll x, y; cin >> x >> y;
        pawn[i] = {x, y};
    }
    sort(all(pawn));

    set<ll> pos{N};
    vector<ll> ins, era;
    ll pre_x = -1;
    for(auto p:pawn){
        ll x = p.first, y = p.second;
        //cout << "x:" << x << " y:" << y << ln;
        if(x != pre_x){
            //cout << "execute!" << ln;
            pre_x = x;
            for(auto p:era)pos.erase(p);
            for(auto p:ins)pos.insert(p);
            ins.clear();
            era.clear();
        }
        //cout << "pos: ";
        //for(auto s:pos)cout << s << " ";cout << ln;
        //not find
        if(pos.find(y-1) == pos.end() and pos.find(y+1) == pos.end()){
            era.push_back(y);
            //cout << "erase:" << y << ln;
        }
        //find
        else{
            ins.push_back(y);
            //cout << "insert:" << y << ln;
        }
    }
    for(auto p:era)pos.erase(p);
    for(auto p:ins)pos.insert(p);
    cout << pos.size() << ln;
}

#include <cstdio>
#include <algorithm>
#define ll long long int
int N, P[200010];
int need[200010], nxd;
int a[200010], r[200010];
void msort(int s, int t)
{
	if(s==t) return;
	int mid = (s+t)/2;
	msort(s, mid);
	msort(mid+1, t);
	int i = s, j = mid+1, k = s;
	while(i<=mid&&j<=t)
	{
		if(a[i]<=a[j])
		{
			r[k] = a[i]; i++; k++;
		}
		else
		{
			r[k] = a[j]; j++; k++;
			nxd += mid-i+1;
		}
	}
	while(i<=mid)
	{
		r[k] = a[i]; i++; k++;
	}
	while(j<=t)
	{
		r[k] = a[j]; j++; k++;
	}
	for(i=s;i<=t;i++) 
	    a[i] = r[i];
}
int main()
{
	scanf("%d", &N);
	for(int i=1;i<=N;i++)
	{
		scanf("%d", &P[i]);
		a[i] = P[i];
		if(P[i]>i)
			need[i] = P[i]-i;
		else
		    need[i] = 0;
	}
	msort(1, N);
//	printf("nxd = %d\n", nxd);
	if(nxd!=(N-1))
	{
		printf("-1\n");
		return 0;
	}
	
/*	for(int i=1;i<=N;i++)
	    printf("%d ", need[i]);
	printf("\n");    
	*/
	
	for(int i=N-1;i>=1;i--)
	{
		int p = i;
		while(need[i])
		{
			printf("%d\n", p);
			p++;
			need[i]--;
		}
	}
	return 0;
}