/*
                                                     _         _   _
                                                    (_)       | | | |
 _ __  _ __ ___   __ _ _ __ __ _ _ __ ___  _ __ ___  _ ___ ___| |_| |_
| '_ \| '__/ _ \ / _` | '__/ _` | '_ ` _ \| '_ ` _ \| / __/ __| __| __|
| |_) | | | (_) | (_| | | | (_| | | | | | | | | | | | \__ \__ \ |_| |_
| .__/|_|  \___/ \__, |_|  \__,_|_| |_| |_|_| |_| |_|_|___/___/\__|\__|
| |               __/ |
|_|              |___/

*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("Ofast")
//#pragma optimize("O3")

typedef long long ll;
typedef unsigned long long ull;

using namespace std;
using namespace __gnu_pbds;

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff first
#define ss second
#define ss1 second.first
#define ss2 second.second
#define forn(i, n) for(int i=0;i<n;i++)
#define fore(i, l, r) for(int i=l;i<r;i++)
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int>
#define vpi vector<pi>
#define gcd(a,b) __gcd(a,b)
#define FASTIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define smp(x,y) {min(x,y),max(x,y)}
#define sqr(x) ((x)*(x))
#define newstr cout << "\n"
#define call(a) {for(auto xxx:a)cout<<xxx<<" ";cout<<"\n";}
#define FILE
const string alf = "abcdefghijklmnopqrstuvwxyz";
const int hashP = 239017;
const int N = 1e5+10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const int INF = 1e9;
const ll oo = 9e18;

template<typename T>
bool umn(T &a, T b) { return (a > b ? (a = b, 1) : 0); }
template<typename T>
bool umx(T &a, T b) { return (a < b ? (a = b, 1) : 0); }

template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // order_of_key    find_by_order

set <ll> s;

void up(ll& x) {
    while(1) {
        if(s.find(x)==s.end()) break;
        x++;
    }
}

int main() {

    FASTIO;

#ifndef FILE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif

    ll tt;
    tt=1;
    while(tt--) {
        ll n;
        cin >> n;
        vector <ll> a(n);
        for(auto& now : a) cin >> now;
        vector <ll> b(n,-1);
        s.clear();
        vector <ll> pos;
        if(a[0]==1) {
            b[0]=0;
            s.insert(0);
        } else {
            pos.push_back(0);
        }
        ll cnt=0;
        for(int i=1;i<n;i++) {
            if(a[i]==a[i-1]) {
                cnt++;
                pos.push_back(i);
            }
            else {
                b[i]=a[i-1];
                s.insert(a[i-1]);
                ll last = a[i-1];
                up(last);
                if(last==a[i]) {
                   // cnt--;
                    continue;
                }
                while(cnt--) {
                    if(pos.size()==0) break;
                    b[pos.back()]=last;
                    pos.pop_back();
                    s.insert(last);
                    if(last==a[i]-1) {
                        last++;
                        break;
                    }
                    last++;
                }
               /* if(last!=a[i]) {
                    cout << "-1";
                    return 0;
                }*/
            }
        }
        for(auto& now : b) if(now==-1) now=1e6;
        call(b);
    }

    return 0;
}


/*
                                                     _         _   _
                                                    (_)       | | | |
 _ __  _ __ ___   __ _ _ __ __ _ _ __ ___  _ __ ___  _ ___ ___| |_| |_
| '_ \| '__/ _ \ / _` | '__/ _` | '_ ` _ \| '_ ` _ \| / __/ __| __| __|
| |_) | | | (_) | (_| | | | (_| | | | | | | | | | | | \__ \__ \ |_| |_
| .__/|_|  \___/ \__, |_|  \__,_|_| |_| |_|_| |_| |_|_|___/___/\__|\__|
| |               __/ |
|_|              |___/

*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("Ofast")
//#pragma optimize("O3")

typedef long long ll;
typedef unsigned long long ull;

using namespace std;
using namespace __gnu_pbds;

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff first
#define ss second
#define ss1 second.first
#define ss2 second.second
#define forn(i, n) for(int i=0;i<n;i++)
#define fore(i, l, r) for(int i=l;i<r;i++)
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int>
#define vpi vector<pi>
#define gcd(a,b) __gcd(a,b)
#define FASTIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define smp(x,y) {min(x,y),max(x,y)}
#define sqr(x) ((x)*(x))
#define newstr cout << "\n"
#define call(a) {for(auto xxx:a)cout<<xxx<<" ";cout<<"\n";}
#define FILE
const string alf = "abcdefghijklmnopqrstuvwxyz";
const int hashP = 239017;
const int N = 1e5+10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const int INF = 1e9;
const ll oo = 9e18;

template<typename T>
bool umn(T &a, T b) { return (a > b ? (a = b, 1) : 0); }
template<typename T>
bool umx(T &a, T b) { return (a < b ? (a = b, 1) : 0); }

template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // order_of_key    find_by_order

set <ll> s;

void up(ll& x) {
    while(1) {
        if(s.find(x)==s.end()) break;
        x++;
    }
}

int main() {

    FASTIO;

#ifndef FILE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif

    ll tt;
    tt=1;
    while(tt--) {
        ll n;
        cin >> n;
        vector <ll> a(n);
        for(auto& now : a) cin >> now;
        vector <ll> b(n,-1);
        s.clear();
        if(a[0]==1) {
            b[0]=0;
            s.insert(0);
        } else {
            b[0]=1;
            s.insert(1);
        }
        ll cnt=0;
        vector <ll> pos;
        for(int i=1;i<n;i++) {
            if(a[i]==a[i-1]) {
                cnt++;
                pos.push_back(i);
            }
            else {
                b[i]=a[i-1];
                s.insert(a[i-1]);
                ll last = a[i-1];
                up(last);
                if(last==a[i]) {
                   // cnt--;
                    continue;
                }
                while(cnt--) {
                    if(pos.size()>0);
                    b[pos.back()]=last;
                    pos.pop_back();
                    s.insert(last);
                    if(last==a[i]-1) {
                        last++;
                        break;
                    }
                    last++;
                }
               /* if(last!=a[i]) {
                    cout << "-1";
                    return 0;
                }*/
            }
        }
        for(auto& now : b) if(now==-1) now=1e6;
        call(b);
    }

    return 0;
}


/*
                                                     _         _   _
                                                    (_)       | | | |
 _ __  _ __ ___   __ _ _ __ __ _ _ __ ___  _ __ ___  _ ___ ___| |_| |_
| '_ \| '__/ _ \ / _` | '__/ _` | '_ ` _ \| '_ ` _ \| / __/ __| __| __|
| |_) | | | (_) | (_| | | | (_| | | | | | | | | | | | \__ \__ \ |_| |_
| .__/|_|  \___/ \__, |_|  \__,_|_| |_| |_|_| |_| |_|_|___/___/\__|\__|
| |               __/ |
|_|              |___/

*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("Ofast")
//#pragma optimize("O3")

typedef long long ll;
typedef unsigned long long ull;

using namespace std;
using namespace __gnu_pbds;

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff first
#define ss second
#define ss1 second.first
#define ss2 second.second
#define forn(i, n) for(int i=0;i<n;i++)
#define fore(i, l, r) for(int i=l;i<r;i++)
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int>
#define vpi vector<pi>
#define gcd(a,b) __gcd(a,b)
#define FASTIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define smp(x,y) {min(x,y),max(x,y)}
#define sqr(x) ((x)*(x))
#define newstr cout << "\n"
#define call(a) {for(auto xxx:a)cout<<xxx<<" ";cout<<"\n";}
#define FILE
const string alf = "abcdefghijklmnopqrstuvwxyz";
const int hashP = 239017;
const int N = 1e5+10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const int INF = 1e9;
const ll oo = 9e18;

template<typename T>
bool umn(T &a, T b) { return (a > b ? (a = b, 1) : 0); }
template<typename T>
bool umx(T &a, T b) { return (a < b ? (a = b, 1) : 0); }

template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // order_of_key    find_by_order

set <ll> s;

void up(ll& x) {
    while(1) {
        if(s.find(x)==s.end()) break;
        x++;
    }
}

int main() {

    FASTIO;

#ifndef FILE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif

    ll tt;
    tt=1;
    while(tt--) {
        ll n;
        cin >> n;
        vector <ll> a(n);
        for(auto& now : a) cin >> now;
        vector <ll> b(n,-1);
        s.clear();
        vector <ll> pos;
        ll cnt=0;
        if(a[0]==1) {
            b[0]=0;
            s.insert(0);
        } else {
            pos.push_back(0);
            cnt++;
        }
        for(int i=1;i<n;i++) {
            if(a[i]==a[i-1]) {
                cnt++;
                pos.push_back(i);
            }
            else {
                b[i]=a[i-1];
                s.insert(a[i-1]);
                ll last = a[i-1];
                up(last);
                if(last==a[i]) {
                   // cnt--;
                    continue;
                }
                while(cnt--) {
                    if(pos.size()==0) break;
                    b[pos.back()]=last;
                    pos.pop_back();
                    s.insert(last);
                    if(last==a[i]-1) {
                        last++;
                        break;
                    }
                    last++;
                }
               /* if(last!=a[i]) {
                    cout << "-1";
                    return 0;
                }*/
            }
        }
        for(auto& now : b) if(now==-1) now=1e6;
        call(b);
    }

    return 0;
}


/*
                                                     _         _   _
                                                    (_)       | | | |
 _ __  _ __ ___   __ _ _ __ __ _ _ __ ___  _ __ ___  _ ___ ___| |_| |_
| '_ \| '__/ _ \ / _` | '__/ _` | '_ ` _ \| '_ ` _ \| / __/ __| __| __|
| |_) | | | (_) | (_| | | | (_| | | | | | | | | | | | \__ \__ \ |_| |_
| .__/|_|  \___/ \__, |_|  \__,_|_| |_| |_|_| |_| |_|_|___/___/\__|\__|
| |               __/ |
|_|              |___/

*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("Ofast")
//#pragma optimize("O3")

typedef long long ll;
typedef unsigned long long ull;

using namespace std;
using namespace __gnu_pbds;

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff first
#define ss second
#define ss1 second.first
#define ss2 second.second
#define forn(i, n) for(int i=0;i<n;i++)
#define fore(i, l, r) for(int i=l;i<r;i++)
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int>
#define vpi vector<pi>
#define gcd(a,b) __gcd(a,b)
#define FASTIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define smp(x,y) {min(x,y),max(x,y)}
#define sqr(x) ((x)*(x))
#define newstr cout << "\n"
#define call(a) {for(auto xxx:a)cout<<xxx<<" ";cout<<"\n";}
#define FILE
const string alf = "abcdefghijklmnopqrstuvwxyz";
const int hashP = 239017;
const int N = 1e5+10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const int INF = 1e9;
const ll oo = 9e18;

template<typename T>
bool umn(T &a, T b) { return (a > b ? (a = b, 1) : 0); }
template<typename T>
bool umx(T &a, T b) { return (a < b ? (a = b, 1) : 0); }

template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // order_of_key    find_by_order

set <ll> s;

void up(ll& x) {
    while(1) {
        if(s.find(x)==s.end()) break;
        x++;
    }
}

int main() {

    FASTIO;

#ifndef FILE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif

    ll tt;
    tt=1;
    while(tt--) {
        ll n;
        cin >> n;
        vector <ll> a(n);
        for(auto& now : a) cin >> now;
        vector <ll> b(n,-1);
        s.clear();
        if(a[0]==1) {
            b[0]=0;
            s.insert(0);
        } else {
            b[0]=1;
            s.insert(1);
        }
        ll cnt=0;
        vector <ll> pos;
        for(int i=1;i<n;i++) {
            if(a[i]==a[i-1]) {
                cnt++;
                pos.push_back(i);
            }
            else {
                b[i]=a[i-1];
                s.insert(a[i-1]);
                ll last = a[i-1];
                up(last);
                if(last==a[i]) {
                   // cnt--;
                    continue;
                }
                while(cnt--) {
                    if(pos.size()==0) break;
                    b[pos.back()]=last;
                    pos.pop_back();
                    s.insert(last);
                    if(last==a[i]-1) {
                        last++;
                        break;
                    }
                    last++;
                }
               /* if(last!=a[i]) {
                    cout << "-1";
                    return 0;
                }*/
            }
        }
        for(auto& now : b) if(now==-1) now=1e6;
        call(b);
    }

    return 0;
}


/*
                                                     _         _   _
                                                    (_)       | | | |
 _ __  _ __ ___   __ _ _ __ __ _ _ __ ___  _ __ ___  _ ___ ___| |_| |_
| '_ \| '__/ _ \ / _` | '__/ _` | '_ ` _ \| '_ ` _ \| / __/ __| __| __|
| |_) | | | (_) | (_| | | | (_| | | | | | | | | | | | \__ \__ \ |_| |_
| .__/|_|  \___/ \__, |_|  \__,_|_| |_| |_|_| |_| |_|_|___/___/\__|\__|
| |               __/ |
|_|              |___/

*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("Ofast")
//#pragma optimize("O3")

typedef long long ll;
typedef unsigned long long ull;

using namespace std;
using namespace __gnu_pbds;

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff first
#define ss second
#define ss1 second.first
#define ss2 second.second
#define forn(i, n) for(int i=0;i<n;i++)
#define fore(i, l, r) for(int i=l;i<r;i++)
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int>
#define vpi vector<pi>
#define gcd(a,b) __gcd(a,b)
#define FASTIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define smp(x,y) {min(x,y),max(x,y)}
#define sqr(x) ((x)*(x))
#define newstr cout << "\n"
#define call(a) {for(auto xxx:a)cout<<xxx<<" ";cout<<"\n";}
#define FILE
const string alf = "abcdefghijklmnopqrstuvwxyz";
const int hashP = 239017;
const int N = 1e5+10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const int INF = 1e9;
const ll oo = 9e18;

template<typename T>
bool umn(T &a, T b) { return (a > b ? (a = b, 1) : 0); }
template<typename T>
bool umx(T &a, T b) { return (a < b ? (a = b, 1) : 0); }

template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // order_of_key    find_by_order

set <ll> s;

void up(ll& x) {
    while(1) {
        if(s.find(x)==s.end()) break;
        x++;
    }
}

int main() {

    FASTIO;

#ifndef FILE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif

    ll tt;
    tt=1;
    while(tt--) {
        ll n;
        cin >> n;
        vector <ll> a(n);
        for(auto& now : a) cin >> now;
        vector <ll> b(n,-1);
        s.clear();
        if(a[0]==1) {
            b[0]=0;
            s.insert(0);
        } else {
            b[0]=1;
            s.insert(1);
        }
        ll cnt=0;
        for(int i=1;i<n;i++) {
            if(a[i]==a[i-1]) cnt++;
            else {
                b[i]=a[i-1];
                s.insert(a[i-1]);
                ll last = a[i-1];
                up(last);
                if(last==a[i]) {
                    continue;
                }
                for(int j=i-1;j>=i-cnt;j--) {
                    b[j]=last;
                    s.insert(last);
                    if(last==a[i]-1) break;
                    last++;
                }
                if(last!=a[i]-1) {
                    cout << "-1";
                    return 0;
                }
                cnt=0;
            }
        }
        for(auto& now : b) if(now==-1) now=1e6;
        call(b);
    }

    return 0;
}


/*
                                                     _         _   _
                                                    (_)       | | | |
 _ __  _ __ ___   __ _ _ __ __ _ _ __ ___  _ __ ___  _ ___ ___| |_| |_
| '_ \| '__/ _ \ / _` | '__/ _` | '_ ` _ \| '_ ` _ \| / __/ __| __| __|
| |_) | | | (_) | (_| | | | (_| | | | | | | | | | | | \__ \__ \ |_| |_
| .__/|_|  \___/ \__, |_|  \__,_|_| |_| |_|_| |_| |_|_|___/___/\__|\__|
| |               __/ |
|_|              |___/

*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("Ofast")
//#pragma optimize("O3")

typedef long long ll;
typedef unsigned long long ull;

using namespace std;
using namespace __gnu_pbds;

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff first
#define ss second
#define ss1 second.first
#define ss2 second.second
#define forn(i, n) for(int i=0;i<n;i++)
#define fore(i, l, r) for(int i=l;i<r;i++)
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int>
#define vpi vector<pi>
#define gcd(a,b) __gcd(a,b)
#define FASTIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define smp(x,y) {min(x,y),max(x,y)}
#define sqr(x) ((x)*(x))
#define newstr cout << "\n"
#define call(a) {for(auto xxx:a)cout<<xxx<<" ";cout<<"\n";}
#define FILE
const string alf = "abcdefghijklmnopqrstuvwxyz";
const int hashP = 239017;
const int N = 1e5+10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const int INF = 1e9;
const ll oo = 9e18;

template<typename T>
bool umn(T &a, T b) { return (a > b ? (a = b, 1) : 0); }
template<typename T>
bool umx(T &a, T b) { return (a < b ? (a = b, 1) : 0); }

template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // order_of_key    find_by_order

set <ll> s;

void up(ll& x) {
    while(1) {
        if(s.find(x)==s.end()) break;
        x++;
    }
}

int main() {

    FASTIO;

#ifndef FILE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif

    ll tt;
    tt=1;
    while(tt--) {
        ll n;
        cin >> n;
        vector <ll> a(n);
        for(auto& now : a) cin >> now;
        vector <ll> b(n,-1);
        s.clear();
        if(a[0]==1) {
            b[0]=0;
            s.insert(0);
        } else {
            b[0]=0;
            pos.push_back(0);
        }
        ll cnt=0;
        vector <ll> pos;
        for(int i=1;i<n;i++) {
            if(a[i]==a[i-1]) {
                cnt++;
                pos.push_back(i);
            }
            else {
                b[i]=a[i-1];
                s.insert(a[i-1]);
                ll last = a[i-1];
                up(last);
                if(last==a[i]) {
                   // cnt--;
                    continue;
                }
                while(cnt--) {
                    if(pos.size()==0) break;
                    b[pos.back()]=last;
                    pos.pop_back();
                    s.insert(last);
                    if(last==a[i]-1) {
                        last++;
                        break;
                    }
                    last++;
                }
               /* if(last!=a[i]) {
                    cout << "-1";
                    return 0;
                }*/
            }
        }
        for(auto& now : b) if(now==-1) now=1e6;
        call(b);
    }

    return 0;
}


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

int main() {
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i ++) cin >> a[i];
	int l = 0;
	bool f = 0;
	for(int i = 0; i < n; i++){
		if(a[i] > l + 1) f = 1;

		l++;
	}
	if(f){
		cout << -1;
		return 0;
	}

	set<int> s;
	for(auto x : a) s.insert(x);
	int k = 0;
	int b[n];
	for(int i = 0; i < n; i++){
		if(*s.begin() < a[i] && *s.begin() < k){
			b[i] = *s.begin();
			s.erase(*s.begin());
		}
		else {
			b[i] = k;
			++k;
		}
	}
	for(auto x : b) cout<<x<<" ";
	return 0;
}


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

int main() {
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i ++) cin >> a[i];
	int l = 0;
	bool f = 0;
	for(int i = 0; i < n; i++){
		if(a[i] > l + 1) f = 1;
		l++;
	}
	if(f){
		cout << -1;
		return 0;
	}

	set<int> s;
	for(auto x : a) s.insert(x);
	int k = 0;
	int b[n];
	for(int i = 0; i < n; i++){
		if(*s.begin() < a[i] && *s.begin() < k){
			b[i] = *s.begin();
			s.erase(*s.begin());
		}
		else {
			b[i] = k;
			++k;
		}
	}
	for(auto x : b) cout<<x<<" ";
	return 0;
}


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

int main() {
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i ++) cin >> a[i];
	int l = 0;
	bool f = 0;
	for(int i = 0; i < n; i++){
		if(a[i] > l + 1) f = 1;
		l++;
	}
	if(f){
		cout << -1;
		return;
	}

	set<int> s;
	for(auto x : a) s.insert(a[i]);
	int k = 0;
	int b[n];
	for(int i = 0; i < n; i++){
		if(*s.begin() < a[i] && *s.begin() < k){
			b[i] = *s.begin();
			s.erase(*s.begin());
		}
		else {
			b[i] = k;
			++k;
		}
	}
	for(auto x : b) cout<<x<<" ";

}


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

int main() {
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i ++) cin >> a[i];
	int l = 0;
	bool f = 0;
	for(int i = 0; i < n; i++){
		if(a[i] > l + 1) f = 1;
		l++;
	}
	if(f){
		cout << -1;
		return;
	}

	set<int> s;
	for(auto x : a) s.insert(x);
	int k = 0;
	int b[n];
	for(int i = 0; i < n; i++){
		if(*s.begin() < a[i] && *s.begin() < k){
			b[i] = *s.begin();
			s.erase(*s.begin());
		}
		else {
			b[i] = k;
			++k;
		}
	}
	for(auto x : b) cout<<x<<" ";
	return 0;
}


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

int main() {
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i ++) cin >> a[i];
	int l = 0;
	bool f = 0;
	for(int i = 0; i < n; i++){
		if(a[i] > l + 1) f = 1;
		l++;
	}
	if(f){
		cout << -1;
		return;
	}

	set<int> s;
	for(auto x : a) s.insert(x);
	int k = 0;
	int b[n];
	for(int i = 0; i < n; i++){
		if(*s.begin() < a[i] && *s.begin() < k){
			b[i] = *s.begin();
			s.erase(*s.begin());
		}
		else {
			b[i] = k;
			++k;
		}
	}
	for(auto x : b) cout<<x<<" ";

}


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

int main() {
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i ++) cin >> a[i];
	int l = 0;
	for(int i = 0; i < n; i++){
		if(a[i] > l + 1) f = 1;
		l++;
	}
	if(f){
		cout << -1;
		return;
	}

	set<int> s;
	for(auto x : a) s.insert(a[i]);
	int k = 0;
	int b[n];
	for(int i = 0; i < n; i++){
		if(*s.begin() < a[i] && *s.begin() < k){
			b[i] = *s.begin();
			s.erase(*s.begin());
		}
		else {
			b[i] = k;
			++k;
		}
	}
	for(auto x : b) cout<<x<<" ";

}


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

int main() {
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i ++) cin >> a[i];
	int l = 0;
	bool f = 0;
	for(int i = 0; i < n; i++){
		if(a[i] > l + 1) f = 1;
		l++;
	}
	if(f){
		cout << -1;
		return 0;
	}

	set<int> s;
	for(auto x : a) s.insert(x);
	int k = 0;
	int b[n];
	for(int i = 0; i < n; i++){
		if(*s.begin() < a[i] && *s.begin() < k-1){
			b[i] = *s.begin();
			s.erase(*s.begin());
		}
		else {
			b[i] = k;
			++k;
		}
	}
	for(auto x : b) cout<<x<<" ";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int arr[MAX];
bool mark[MAX];
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>arr[i];
    vector<int>v;
    if(arr[0]==0)
    {
        v.push_back(1);
        int next_num=2;
        for(int i=1; i<n; i++)
        {
            if(arr[i]!=arr[i-1] && arr[i]!=next_num)
            {
                if(arr[i]-1==i)
                {
                    mark[i]=1;
                    v.push_back(arr[i-1]);
                    continue;
                }
                cout<<"-1"<<endl;
                return 0;
            }
            else if(arr[i]==arr[i-1])
            {
                int sz=v.size();
                v.push_back(v[sz-1]);
            }
            else if(arr[i]==next_num)
            {
                if(arr[i]==0)
                    v.push_back(1);
                else if(arr[i]==2)
                    v.push_back(0);
                else
                    v.push_back(arr[i]-1);
                next_num++;
            }
        }
        /*for(auto x:v)
            cout<<x<<" ";
        cout<<endl;*/
        int cur=-1;
        for(int i=n-1; i>=0; i--)
        {
            if(cur>-1)
            {
                if(v[i]==v[i+1])
                {
                    v[i+1]=cur--;
                }
            }
            if(mark[i])
            {
                cur=arr[i]-1;
            }
        }
        for(auto x:v)
            cout<<x<<" ";
    }
    else if(arr[0]==1)
    {
        v.push_back(0);
        int next_num=2;
        for(int i=1; i<n; i++)
        {
            if(arr[i]!=arr[i-1] && arr[i]!=next_num)
            {
                if(arr[i]-1==i)
                {
                    mark[i]=1;
                    v.push_back(arr[i-1]);
                    continue;
                }
                cout<<"-1"<<endl;
                return 0;
            }
            else if(arr[i]==arr[i-1])
            {
                int sz=v.size();
                v.push_back(v[sz-1]);
            }
            else if(arr[i]==next_num)
            {
                v.push_back(arr[i]-1);
                next_num++;
            }
        }
        int cur=-1;
        for(int i=n-1; i>=0; i--)
        {
            if(cur>-1)
            {
                if(v[i]==v[i+1])
                {
                    v[i+1]=cur--;
                }
            }
            if(mark[i])
            {
                cur=arr[i]-1;
            }
        }
        for(auto x:v)
            cout<<x<<" ";
    }
    else
        cout<<"-1"<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int arr[MAX];
bool mark[MAX];
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>arr[i];
    vector<int>v;
    if(arr[0]==0)
    {
        v.push_back(1);
        int next_num=2;
        for(int i=1; i<n; i++)
        {
            if(arr[i]==1)
            {
                cout<<"-1"<<endl;
                return 0;
            }
            if(arr[i]!=arr[i-1] && arr[i]!=next_num)
            {
                if(arr[i]-1<=i)
                {
                    mark[i]=1;
                    v.push_back(arr[i-1]);
                    next_num=arr[i]+1;
                    continue;
                }
                cout<<"-1"<<endl;
                return 0;
            }
            else if(arr[i]==arr[i-1])
            {
                int sz=v.size();
                v.push_back(v[sz-1]);
            }
            else if(arr[i]==next_num)
            {
                if(arr[i]==0)
                    v.push_back(1);
                else if(arr[i]==2)
                    v.push_back(0);
                else
                    v.push_back(arr[i]-1);
                next_num++;
            }
        }
        /*for(auto x:v)
            cout<<x<<" ";
        cout<<endl;*/
        queue<int>q;
        int cur=INT_MAX,last=INT_MAX;
        for(int i=n-1; i>=0; i--)
        {
            if(v[i]==v[i+1] && q.size())
            {
                v[i+1]=q.front();
                q.pop();
            }
            if(mark[i])
            {
                for(int j=arr[i]-1; j>v[i]; j--)
                    q.push(j);
            }
        }
        for(auto x:v)
            cout<<x<<" ";
    }
    else if(arr[0]==1)
    {
        v.push_back(0);
        int next_num=2;
        for(int i=1; i<n; i++)
        {
            if(arr[i]!=arr[i-1] && arr[i]!=next_num)
            {
                if(arr[i]-1<=i)
                {
                    mark[i]=1;
                    v.push_back(arr[i-1]);
                    next_num=arr[i]+1;
                    continue;
                }
                cout<<"-1"<<endl;
                return 0;
            }
            else if(arr[i]==arr[i-1])
            {
                int sz=v.size();
                v.push_back(v[sz-1]);
            }
            else if(arr[i]==next_num)
            {
                v.push_back(arr[i]-1);
                next_num++;
            }
        }
        queue<int>q;
        int cur=INT_MAX,last=INT_MAX;
        for(int i=n-1; i>=0; i--)
        {
            if(v[i]==v[i+1] && q.size())
            {
                v[i+1]=q.front();
                q.pop();
            }
            if(mark[i])
            {
                for(int j=arr[i]-1; j>v[i]; j--)
                    q.push(j);
            }
        }
        for(auto x:v)
            cout<<x<<" ";
    }
    else
        cout<<"-1"<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int arr[MAX];
bool mark[MAX];
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>arr[i];
    vector<int>v;
    if(arr[0]==0)
    {
        v.push_back(1);
        int next_num=2;
        for(int i=1; i<n; i++)
        {
            if(arr[i]==1){
                cout<<"-1"<<endl;
                return 0;
            }
            if(arr[i]!=arr[i-1] && arr[i]!=next_num)
            {
                if(arr[i]-1<=i)
                {
                    mark[i]=1;
                    v.push_back(arr[i-1]);
                    next_num=arr[i]+1;
                    continue;
                }
                cout<<"-1"<<endl;
                return 0;
            }
            else if(arr[i]==arr[i-1])
            {
                int sz=v.size();
                v.push_back(v[sz-1]);
            }
            else if(arr[i]==next_num)
            {
                if(arr[i]==0)
                    v.push_back(1);
                else if(arr[i]==2)
                    v.push_back(0);
                else
                    v.push_back(arr[i]-1);
                next_num++;
            }
        }
        /*for(auto x:v)
            cout<<x<<" ";
        cout<<endl;*/
        int cur=INT_MAX,last=INT_MAX;
        for(int i=n-1; i>=0; i--)
        {
            if(cur!=last)
            {
                if(v[i]==v[i+1])
                {
                    v[i+1]=cur--;
                }
            }
            if(mark[i])
            {
                cur=arr[i]-1;
                last=v[i];
            }
        }
        for(auto x:v)
            cout<<x<<" ";
    }
    else if(arr[0]==1)
    {
        v.push_back(0);
        int next_num=2;
        for(int i=1; i<n; i++)
        {
            if(arr[i]!=arr[i-1] && arr[i]!=next_num)
            {
                if(arr[i]-1<=i)
                {
                    mark[i]=1;
                    v.push_back(arr[i-1]);
                    next_num=arr[i]+1;
                    continue;
                }
                cout<<"-1"<<endl;
                return 0;
            }
            else if(arr[i]==arr[i-1])
            {
                int sz=v.size();
                v.push_back(v[sz-1]);
            }
            else if(arr[i]==next_num)
            {
                v.push_back(arr[i]-1);
                next_num++;
            }
        }
        int cur=INT_MAX,last=INT_MAX;
        for(int i=n-1; i>=0; i--)
        {
            if(cur!=last)
            {
                if(v[i]==v[i+1])
                {
                    v[i+1]=cur--;
                }
            }
            if(mark[i])
            {
                cur=arr[i]-1;
                last=v[i];
            }
        }
        for(auto x:v)
            cout<<x<<" ";
    }
    else
        cout<<"-1"<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int arr[MAX];
bool mark[MAX];
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>arr[i];
    vector<int>v;
    if(arr[0]==0)
    {
        v.push_back(1);
        int next_num=2;
        for(int i=1; i<n; i++)
        {
            if(arr[i]!=arr[i-1] && arr[i]!=next_num)
            {
                if(arr[i]-1<=i)
                {
                    mark[i]=1;
                    v.push_back(arr[i-1]);
                    next_num=arr[i]+1;
                    continue;
                }
                cout<<"-1"<<endl;
                return 0;
            }
            else if(arr[i]==arr[i-1])
            {
                int sz=v.size();
                v.push_back(v[sz-1]);
            }
            else if(arr[i]==next_num)
            {
                if(arr[i]==0)
                    v.push_back(1);
                else if(arr[i]==2)
                    v.push_back(0);
                else
                    v.push_back(arr[i]-1);
                next_num++;
            }
        }
        /*for(auto x:v)
            cout<<x<<" ";
        cout<<endl;*/
        queue<int>q;
        int cur=INT_MAX,last=INT_MAX;
        for(int i=n-1; i>=0; i--)
        {
            if(mark[i])
            {
                for(int j=arr[i]-1; j>v[i]; j--)
                    q.push(j);
            }
        }
        for(int i=0; i<n; i++)
        {
            if(v[i]==v[i+1]&& q.size())
            {
                v[i]=q.front();
                q.pop();
            }

        }
        for(auto x:v)
            cout<<x<<" ";
    }
    else if(arr[0]==1)
    {
        v.push_back(0);
        int next_num=2;
        for(int i=1; i<n; i++)
        {
            if(arr[i]!=arr[i-1] && arr[i]!=next_num)
            {
                if(arr[i]-1<=i)
                {
                    mark[i]=1;
                    v.push_back(arr[i-1]);
                    next_num=arr[i]+1;
                    continue;
                }
                cout<<"-1"<<endl;
                return 0;
            }
            else if(arr[i]==arr[i-1])
            {
                int sz=v.size();
                v.push_back(v[sz-1]);
            }
            else if(arr[i]==next_num)
            {
                v.push_back(arr[i]-1);
                next_num++;
            }
        }
        queue<int>q;
        int cur=INT_MAX,last=INT_MAX;
        for(int i=n-1; i>=0; i--)
        {
            if(mark[i])
            {
                for(int j=arr[i]-1; j>v[i]; j--)
                    q.push(j);
            }
        }
        for(int i=0; i<n-1; i++)
        {
            if(v[i]==v[i+1] && q.size())
            {
                v[i]=q.front();
                q.pop();
            }

        }
        for(auto x:v)
            cout<<x<<" ";
    }
    else
        cout<<"-1"<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int arr[MAX];
bool mark[MAX];
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>arr[i];
    vector<int>v;
    if(arr[0]==0)
    {
        v.push_back(1);
        int next_num=2;
        for(int i=1; i<n; i++)
        {
            if(arr[i]==1)
            {
                cout<<"-1"<<endl;
                return 0;
            }
            if(arr[i]!=arr[i-1] && arr[i]!=next_num)
            {
                if(arr[i]-1<=i)
                {
                    mark[i]=1;
                    v.push_back(arr[i-1]);
                    next_num=arr[i]+1;
                    continue;
                }
                cout<<"-1"<<endl;
                return 0;
            }
            else if(arr[i]==arr[i-1])
            {
                int sz=v.size();
                v.push_back(v[sz-1]);
            }
            else if(arr[i]==next_num)
            {
                if(arr[i]==0)
                    v.push_back(1);
                else if(arr[i]==2)
                    v.push_back(0);
                else
                    v.push_back(arr[i]-1);
                next_num++;
            }
        }
        /*for(auto x:v)
            cout<<x<<" ";
        cout<<endl;*/
        queue<int>q;
        int cur=INT_MAX,last=INT_MAX;
        for(int i=n-1; i>=0; i--)
        {
            if(mark[i])
            {
                for(int j=arr[i]-1; j>v[i]; j--)
                    q.push(j);
            }
        }
        for(int i=0; i<n; i++)
        {
            if(v[i]==v[i+1]&& q.size())
            {
                v[i]=q.front();
                q.pop();
            }

        }
        for(auto x:v)
            cout<<x<<" ";
    }
    else if(arr[0]==1)
    {
        v.push_back(0);
        int next_num=2;
        for(int i=1; i<n; i++)
        {
            if(arr[i]!=arr[i-1] && arr[i]!=next_num)
            {
                if(arr[i]-1<=i)
                {
                    mark[i]=1;
                    v.push_back(arr[i-1]);
                    next_num=arr[i]+1;
                    continue;
                }
                cout<<"-1"<<endl;
                return 0;
            }
            else if(arr[i]==arr[i-1])
            {
                int sz=v.size();
                v.push_back(v[sz-1]);
            }
            else if(arr[i]==next_num)
            {
                v.push_back(arr[i]-1);
                next_num++;
            }
        }
        queue<int>q;
        int cur=INT_MAX,last=INT_MAX;
        for(int i=n-1; i>=0; i--)
        {
            if(mark[i])
            {
                for(int j=arr[i]-1; j>v[i]; j--)
                    q.push(j);
            }
        }
        for(int i=0; i<n; i++)
        {
            if(v[i]==v[i+1] && q.size())
            {
                v[i]=q.front();
                q.pop();
            }

        }
        for(auto x:v)
            cout<<x<<" ";
    }
    else
        cout<<"-1"<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int arr[MAX];
bool mark[MAX];
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>arr[i];
    vector<int>v;
    if(arr[0]==0)
    {
        v.push_back(1);
        int next_num=2;
        for(int i=1; i<n; i++)
        {
            if(arr[i]==1)
            {
                cout<<"-1"<<endl;
                return 0;
            }
            if(arr[i]!=arr[i-1] && arr[i]!=next_num)
            {
                if(arr[i]-1<=i)
                {
                    mark[i]=1;
                    v.push_back(arr[i-1]);
                    next_num=arr[i]+1;
                    continue;
                }
                cout<<"-1"<<endl;
                return 0;
            }
            else if(arr[i]==arr[i-1])
            {
                int sz=v.size();
                v.push_back(v[sz-1]);
            }
            else if(arr[i]==next_num)
            {
                if(arr[i]==0)
                    v.push_back(1);
                else if(arr[i]==2)
                    v.push_back(0);
                else
                    v.push_back(arr[i]-1);
                next_num++;
            }
        }
        /*for(auto x:v)
            cout<<x<<" ";
        cout<<endl;*/
        queue<int>q;
        int cur=INT_MAX,last=INT_MAX;
        for(int i=n-1; i>=0; i--)
        {
            if(mark[i])
            {
                for(int j=arr[i]-1; j>v[i]; j--)
                    q.push(j);
            }
        }
        for(int i=0; i<n; i++)
        {
            if(v[i]==v[i+1])
            {
                v[i]=q.front();
                q.pop();
            }

        }
        for(auto x:v)
            cout<<x<<" ";
    }
    else if(arr[0]==1)
    {
        v.push_back(0);
        int next_num=2;
        for(int i=1; i<n; i++)
        {
            if(arr[i]!=arr[i-1] && arr[i]!=next_num)
            {
                if(arr[i]-1<=i)
                {
                    mark[i]=1;
                    v.push_back(arr[i-1]);
                    next_num=arr[i]+1;
                    continue;
                }
                cout<<"-1"<<endl;
                return 0;
            }
            else if(arr[i]==arr[i-1])
            {
                int sz=v.size();
                v.push_back(v[sz-1]);
            }
            else if(arr[i]==next_num)
            {
                v.push_back(arr[i]-1);
                next_num++;
            }
        }
        queue<int>q;
        int cur=INT_MAX,last=INT_MAX;
        for(int i=n-1; i>=0; i--)
        {
            if(mark[i])
            {
                for(int j=arr[i]-1; j>v[i]; j--)
                    q.push(j);
            }
        }
        for(int i=0; i<n; i++)
        {
            if(v[i]==v[i+1])
            {
                v[i]=q.front();
                q.pop();
            }

        }
        for(auto x:v)
            cout<<x<<" ";
    }
    else
        cout<<"-1"<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int arr[MAX];
bool mark[MAX];
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>arr[i];
    vector<int>v;
    if(arr[0]==0)
    {
        v.push_back(1);
        int next_num=2;
        for(int i=1; i<n; i++)
        {
            if(arr[i]!=arr[i-1] && arr[i]!=next_num)
            {
                if(arr[i]-1<=i)
                {
                    mark[i]=1;
                    v.push_back(arr[i-1]);
                    next_num=arr[i]+1;
                    continue;
                }
                cout<<"-1"<<endl;
                return 0;
            }
            else if(arr[i]==arr[i-1])
            {
                int sz=v.size();
                v.push_back(v[sz-1]);
            }
            else if(arr[i]==next_num)
            {
                if(arr[i]==0)
                    v.push_back(1);
                else if(arr[i]==2)
                    v.push_back(0);
                else
                    v.push_back(arr[i]-1);
                next_num++;
            }
        }
        /*for(auto x:v)
            cout<<x<<" ";
        cout<<endl;*/
        int cur=INT_MAX,last=INT_MAX;
        for(int i=n-1; i>=0; i--)
        {
            if(cur!=last)
            {
                if(v[i]==v[i+1])
                {
                    v[i+1]=cur--;
                }
            }
            if(mark[i])
            {
                cur=arr[i]-1;
                last=v[i];
            }
        }
        for(auto x:v)
            cout<<x<<" ";
    }
    else if(arr[0]==1)
    {
        v.push_back(0);
        int next_num=2;
        for(int i=1; i<n; i++)
        {
            if(arr[i]!=arr[i-1] && arr[i]!=next_num)
            {
                if(arr[i]-1<=i)
                {
                    mark[i]=1;
                    v.push_back(arr[i-1]);
                    next_num=arr[i]+1;
                    continue;
                }
                cout<<"-1"<<endl;
                return 0;
            }
            else if(arr[i]==arr[i-1])
            {
                int sz=v.size();
                v.push_back(v[sz-1]);
            }
            else if(arr[i]==next_num)
            {
                v.push_back(arr[i]-1);
                next_num++;
            }
        }
        int cur=INT_MAX,last=INT_MAX;
        for(int i=n-1; i>=0; i--)
        {
            if(cur!=last)
            {
                if(v[i]==v[i+1])
                {
                    v[i+1]=cur--;
                }
            }
            if(mark[i])
            {
                cur=arr[i]-1;
                last=v[i];
            }
        }
        for(auto x:v)
            cout<<x<<" ";
    }
    else
        cout<<"-1"<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int arr[MAX];
bool mark[MAX];
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>arr[i];
    vector<int>v;
    if(arr[0]==0)
    {
        v.push_back(1);
        int next_num=2;
        for(int i=1; i<n; i++)
        {

            if(arr[i]!=arr[i-1] && arr[i]!=next_num)
            {
                if(arr[i]-1<=i)
                {
                    mark[i]=1;
                    v.push_back(arr[i-1]);
                    next_num=arr[i]+1;
                    continue;
                }
                cout<<"-1"<<endl;
                return 0;
            }
            else if(arr[i]==arr[i-1])
            {
                int sz=v.size();
                v.push_back(v[sz-1]);
            }
            else if(arr[i]==next_num)
            {
                if(arr[i]==0)
                    v.push_back(1);
                else if(arr[i]==2)
                    v.push_back(0);
                else
                    v.push_back(arr[i]-1);
                next_num++;
            }
        }
        /*for(auto x:v)
            cout<<x<<" ";
        cout<<endl;*/
        queue<int>q;
        int cur=INT_MAX,last=INT_MAX;
        for(int i=n-1; i>=0; i--)
        {
            if(v[i]==v[i+1] && q.size())
            {
                v[i+1]=q.front();
                q.pop();
            }
            if(mark[i])
            {
                for(int j=arr[i]-1; j>v[i]; j--)
                    q.push(j);
            }
        }
        for(auto x:v)
            cout<<x<<" ";
    }
    else if(arr[0]==1)
    {
        v.push_back(0);
        int next_num=2;
        for(int i=1; i<n; i++)
        {
            if(arr[i]!=arr[i-1] && arr[i]!=next_num)
            {
                if(arr[i]-1<=i)
                {
                    mark[i]=1;
                    v.push_back(arr[i-1]);
                    next_num=arr[i]+1;
                    continue;
                }
                cout<<"-1"<<endl;
                return 0;
            }
            else if(arr[i]==arr[i-1])
            {
                int sz=v.size();
                v.push_back(v[sz-1]);
            }
            else if(arr[i]==next_num)
            {
                v.push_back(arr[i]-1);
                next_num++;
            }
        }
        queue<int>q;
        int cur=INT_MAX,last=INT_MAX;
        for(int i=n-1; i>=0; i--)
        {
            if(v[i]==v[i+1] && q.size())
            {
                v[i+1]=q.front();
                q.pop();
            }
            if(mark[i])
            {
                for(int j=arr[i]-1; j>v[i]; j--)
                    q.push(j);
            }
        }
        for(auto x:v)
            cout<<x<<" ";
    }
    else
        cout<<"-1"<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int arr[MAX];
bool mark[MAX];
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>arr[i];
    vector<int>v;
    if(arr[0]==0)
    {
        v.push_back(1);
        int next_num=2;
        for(int i=1; i<n; i++)
        {
            if(arr[i]!=arr[i-1] && arr[i]!=next_num)
            {
                if(arr[i]-1<=i)
                {
                    mark[i]=1;
                    v.push_back(arr[i-1]);
                    continue;
                }
                cout<<"-1"<<endl;
                return 0;
            }
            else if(arr[i]==arr[i-1])
            {
                int sz=v.size();
                v.push_back(v[sz-1]);
            }
            else if(arr[i]==next_num)
            {
                if(arr[i]==0)
                    v.push_back(1);
                else if(arr[i]==2)
                    v.push_back(0);
                else
                    v.push_back(arr[i]-1);
                next_num++;
            }
        }
        /*for(auto x:v)
            cout<<x<<" ";
        cout<<endl;*/
        int cur=-1;
        for(int i=n-1; i>=0; i--)
        {
            if(cur>-1)
            {
                if(v[i]==v[i+1])
                {
                    v[i+1]=cur--;
                }
            }
            if(mark[i])
            {
                cur=arr[i]-1;
            }
        }
        for(auto x:v)
            cout<<x<<" ";
    }
    else if(arr[0]==1)
    {
        v.push_back(0);
        int next_num=2;
        for(int i=1; i<n; i++)
        {
            if(arr[i]!=arr[i-1] && arr[i]!=next_num)
            {
                if(arr[i]-1<=i)
                {
                    mark[i]=1;
                    v.push_back(arr[i-1]);
                    continue;
                }
                cout<<"-1"<<endl;
                return 0;
            }
            else if(arr[i]==arr[i-1])
            {
                int sz=v.size();
                v.push_back(v[sz-1]);
            }
            else if(arr[i]==next_num)
            {
                v.push_back(arr[i]-1);
                next_num++;
            }
        }
        int cur=-1;
        for(int i=n-1; i>=0; i--)
        {
            if(cur>-1)
            {
                if(v[i]==v[i+1])
                {
                    v[i+1]=cur--;
                }
            }
            if(mark[i])
            {
                cur=arr[i]-1;
            }
        }
        for(auto x:v)
            cout<<x<<" ";
    }
    else
        cout<<"-1"<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int arr[MAX];
bool mark[MAX];
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>arr[i];
    vector<int>v;
    if(arr[0]==0)
    {
        v.push_back(1);
        int next_num=2;
        for(int i=1; i<n; i++)
        {
            if(arr[i]!=arr[i-1] && arr[i]!=next_num)
            {
                if(arr[i]-1<=i)
                {
                    mark[i]=1;
                    v.push_back(arr[i-1]);
                    next_num=arr[i]+1;
                    continue;
                }
                cout<<"-1"<<endl;
                return 0;
            }
            else if(arr[i]==arr[i-1])
            {
                int sz=v.size();
                v.push_back(v[sz-1]);
            }
            else if(arr[i]==next_num)
            {
                if(arr[i]==0)
                    v.push_back(1);
                else if(arr[i]==2)
                    v.push_back(0);
                else
                    v.push_back(arr[i]-1);
                next_num++;
            }
        }
        /*for(auto x:v)
            cout<<x<<" ";
        cout<<endl;*/
        int cur=-1;
        for(int i=n-1; i>=0; i--)
        {
            if(cur>-1)
            {
                if(v[i]==v[i+1])
                {
                    v[i+1]=cur--;
                }
            }
            if(mark[i])
            {
                cur=arr[i]-1;
            }
        }
        for(auto x:v)
            cout<<x<<" ";
    }
    else if(arr[0]==1)
    {
        v.push_back(0);
        int next_num=2;
        for(int i=1; i<n; i++)
        {
            if(arr[i]!=arr[i-1] && arr[i]!=next_num)
            {
                if(arr[i]-1<=i)
                {
                    mark[i]=1;
                    v.push_back(arr[i-1]);
                     next_num=arr[i]+1;
                    continue;
                }
                cout<<"-1"<<endl;
                return 0;
            }
            else if(arr[i]==arr[i-1])
            {
                int sz=v.size();
                v.push_back(v[sz-1]);
            }
            else if(arr[i]==next_num)
            {
                v.push_back(arr[i]-1);
                next_num++;
            }
        }
        int cur=-1;
        for(int i=n-1; i>=0; i--)
        {
            if(cur>-1)
            {
                if(v[i]==v[i+1])
                {
                    v[i+1]=cur--;
                }
            }
            if(mark[i])
            {
                cur=arr[i]-1;
            }
        }
        for(auto x:v)
            cout<<x<<" ";
    }
    else
        cout<<"-1"<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e5+5;
#define pi acos(-1)
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int arr[MAX],ans[MAX];
bool mark[MAX];
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    memset(ans, -1, sizeof ans);
    int n;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>arr[i];
        if(arr[i]!=arr[i-1])
        {
            for(int j=i,k=arr[i-1]; k<arr[i]; j--)
                if(ans[j]==-1)
                    ans[j]=k++;
        }
    }
    for(int i=1;i<=n;i++){
        if(ans[i]==-1)
            ans[i]=1e6;
        cout<<ans[i]<<" ";
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int arr[MAX];
bool mark[MAX];
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>arr[i];
    vector<int>v;
    if(arr[0]==0)
    {
        v.push_back(1);
        int next_num=2;
        for(int i=1; i<n; i++)
        {
            if(arr[i]==1)
            {
                cout<<"-1"<<endl;
                return 0;
            }
            if(arr[i]!=arr[i-1] && arr[i]!=next_num)
            {
                if(arr[i]-1<=i)
                {
                    mark[i]=1;
                    v.push_back(arr[i-1]);
                    next_num=arr[i]+1;
                    continue;
                }
                cout<<"-1"<<endl;
                return 0;
            }
            else if(arr[i]==arr[i-1])
            {
                int sz=v.size();
                v.push_back(v[sz-1]);
            }
            else if(arr[i]==next_num)
            {
                if(arr[i]==0)
                    v.push_back(1);
                else if(arr[i]==2)
                    v.push_back(0);
                else
                    v.push_back(arr[i]-1);
                next_num++;
            }
        }
        /*for(auto x:v)
            cout<<x<<" ";
        cout<<endl;*/
        queue<int>q;
        int cur=INT_MAX,last=INT_MAX;
        for(int i=n-1; i>=0; i--)
        {
            if(v[i]==v[i+1] && q.size())
            {
                v[i+1]=q.front();
                q.pop();
            }
            if(mark[i])
            {
                for(int j=v[i]+1; j<arr[i]; j++)
                    q.push(j);
            }
        }
        for(auto x:v)
            cout<<x<<" ";
    }
    else if(arr[0]==1)
    {
        v.push_back(0);
        int next_num=2;
        for(int i=1; i<n; i++)
        {
            if(arr[i]!=arr[i-1] && arr[i]!=next_num)
            {
                if(arr[i]-1<=i)
                {
                    mark[i]=1;
                    v.push_back(arr[i-1]);
                    next_num=arr[i]+1;
                    continue;
                }
                cout<<"-1"<<endl;
                return 0;
            }
            else if(arr[i]==arr[i-1])
            {
                int sz=v.size();
                v.push_back(v[sz-1]);
            }
            else if(arr[i]==next_num)
            {
                v.push_back(arr[i]-1);
                next_num++;
            }
        }
        queue<int>q;
        int cur=INT_MAX,last=INT_MAX;
        for(int i=n-1; i>=0; i--)
        {
            if(v[i]==v[i+1] && q.size())
            {
                v[i+1]=q.front();
                q.pop();
            }
            if(mark[i])
            {
                for(int j=v[i]+1; j<arr[i]; j++)
                    q.push(j);
            }
        }
        for(auto x:v)
            cout<<x<<" ";
    }
    else
        cout<<"-1"<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int arr[MAX];
bool mark[MAX];
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>arr[i];
    vector<int>v;
    if(arr[0]==0)
    {
        v.push_back(1);
        int next_num=1;
        for(int i=1; i<n; i++)
        {

            if(arr[i]!=arr[i-1] && arr[i]!=next_num)
            {
                if(arr[i]-1<=i)
                {
                    mark[i]=1;
                    v.push_back(arr[i-1]);
                    next_num=arr[i]+1;
                    continue;
                }
                cout<<"-1"<<endl;
                return 0;
            }
            else if(arr[i]==arr[i-1])
            {
                int sz=v.size();
                v.push_back(v[sz-1]);
            }
            else if(arr[i]==next_num)
            {
                if(arr[i]==0)
                    v.push_back(1);
                else
                    v.push_back(arr[i]-1);
                next_num++;
            }
        }
        /*for(auto x:v)
            cout<<x<<" ";
        cout<<endl;*/
        queue<int>q;
        int cur=INT_MAX,last=INT_MAX;
        for(int i=n-1; i>=0; i--)
        {
            if(v[i]==v[i+1] && q.size())
            {
                v[i+1]=q.front();
                q.pop();
            }
            if(mark[i])
            {
                for(int j=arr[i]-1; j>v[i]; j--)
                    q.push(j);
            }
        }
        for(auto x:v)
            cout<<x<<" ";
    }
    else if(arr[0]==1)
    {
        v.push_back(0);
        int next_num=2;
        for(int i=1; i<n; i++)
        {
            if(arr[i]!=arr[i-1] && arr[i]!=next_num)
            {
                if(arr[i]-1<=i)
                {
                    mark[i]=1;
                    v.push_back(arr[i-1]);
                    next_num=arr[i]+1;
                    continue;
                }
                cout<<"-1"<<endl;
                return 0;
            }
            else if(arr[i]==arr[i-1])
            {
                int sz=v.size();
                v.push_back(v[sz-1]);
            }
            else if(arr[i]==next_num)
            {
                v.push_back(arr[i]-1);
                next_num++;
            }
        }
        queue<int>q;
        int cur=INT_MAX,last=INT_MAX;
        for(int i=n-1; i>=0; i--)
        {
            if(v[i]==v[i+1] && q.size())
            {
                v[i+1]=q.front();
                q.pop();
            }
            if(mark[i])
            {
                for(int j=arr[i]-1; j>v[i]; j--)
                    q.push(j);
            }
        }
        for(auto x:v)
            cout<<x<<" ";
    }
    else
        cout<<"-1"<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int arr[MAX];
bool mark[MAX];
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>arr[i];
    vector<int>v;
    if(arr[0]==0)
    {
        v.push_back(1);
        int next_num=2;
        for(int i=1; i<n; i++)
        {
            if(arr[i]==1)
            {
                cout<<"-1"<<endl;
                return 0;
            }
            if(arr[i]!=arr[i-1] && arr[i]!=next_num)
            {
                if(arr[i]-1<=i)
                {
                    mark[i]=1;
                    v.push_back(arr[i-1]);
                    next_num=arr[i]+1;
                    continue;
                }
                cout<<"-1"<<endl;
                return 0;
            }
            else if(arr[i]==arr[i-1])
            {
                int sz=v.size();
                v.push_back(v[sz-1]);
            }
            else if(arr[i]==next_num)
            {
                if(arr[i]==0)
                    v.push_back(1);
                else if(arr[i]==2)
                    v.push_back(0);
                else
                    v.push_back(arr[i]-1);
                next_num++;
            }
        }
        /*for(auto x:v)
            cout<<x<<" ";
        cout<<endl;*/
        queue<int>q;
        int cur=INT_MAX,last=INT_MAX;
        for(int i=n-1; i>=0; i--)
        {
            if(v[i]==v[i+1] && q.size())
            {
                v[i+1]=q.front();
                q.pop();
            }
            if(mark[i])
            {
                for(int j=arr[i]-1; j>v[i]; j--)
                    q.push(j);
            }
        }
        for(auto x:v)
            cout<<x<<" ";
    }
    else if(arr[0]==1)
    {
        v.push_back(0);
        int next_num=2;
        for(int i=1; i<n; i++)
        {
            if(arr[i]!=arr[i-1] && arr[i]!=next_num)
            {
                if(arr[i]-1<=i)
                {
                    mark[i]=1;
                    v.push_back(arr[i-1]);
                    next_num=arr[i]+1;
                    continue;
                }
                cout<<"-1"<<endl;
                return 0;
            }
            else if(arr[i]==arr[i-1])
            {
                int sz=v.size();
                v.push_back(v[sz-1]);
            }
            else if(arr[i]==next_num)
            {
                v.push_back(arr[i]-1);
                next_num++;
            }
        }
        queue<int>q;
        int cur=INT_MAX,last=INT_MAX;
        for(int i=n-1; i>=0; i--)
        {
            if(v[i]==v[i+1] && q.size())
            {
                v[i+1]=q.front();
                q.pop();
            }
            if(mark[i])
            {
                for(int j=v; j<arr[i]; j++)
                    q.push(j);
            }
        }
        for(auto x:v)
            cout<<x<<" ";
    }
    else
        cout<<"-1"<<endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back

const double PI = 3.141592653589793;

int main() {
    int t;
    cin >> t;
    while(t--){
        int n, x;
        cin >> n >> x;
        long long sum = 0;
        long long nm = 0;
        int nn = 0;
        for(int i = 0; i < n; i++){
            int a;
            cin >> a;
            if(a % x == 0) {
                nm += a;
            } else{
                sum += a;
                nn++;
            }

        }
        //cout << nn << " " << sum << endl;
        if(nn == 0) cout << -1;
        else if(nn == 1) cout << n;
        else if(sum % x == 0) cout << n - 1;
        else cout << n;
        cout << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back

const double PI = 3.141592653589793;

int main() {
    int t;
    cin >> t;
    while(t--){
        int n, x;
        cin >> n >> x;
        long long sum = 0;
        long long nm = 0;
        int nn = 0;
        int a[n];
        for(int i = 0; i < n; i++){
            cin >> a[i];
            if(a[i] % x == 0) {
                nm += a[i];
            } else{
                sum += a[i];
                nn++;
            }

        }
        //cout << nn << " " << sum << endl;
        if(nn == 0) cout << -1;
        else if(nn == 1) cout << n;
        else if(sum % x == 0){
            int x1, y;
            for(int i = 0; i < n; i++){
                if(a[i] % x != 0){
                    x1 = i;
                    break;
                }
            }
            for(int  i = n - 1; i >= 0; i--){
                if(a[i] % x != 0){
                    y = i;
                    break;
                }
            }
            x1++;
            cout << max(n - x1, y + 1);
        }
        else cout << n;
        cout << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    vector<int> ans{};
    queue<int> q{};
    int last = -1, min = -1;

    if (n == 1)
    {
        int i;
        cin>>i;
        if (i != 1)
            cout << "-1\n";
        else
            cout << "0\n";
        return 0;
    }

    for (int i = 0; i < n; i++)
    {
        int num;
        cin>>num;
        if (num > i+1)
        {
            cout << "-1\n";
            return 0;
        }

        if (last != -1)
        {
            if (last == num)
            {
                q.push(i);
                ans.push_back(1e6);
                continue;
            }
            else
            {
                ans.push_back(last);

                if (num > min + 2)
                {
                    for (int j = 0; j < num-last && min < num - 1; j++)
                    {
                        if (q.size() == 0)
                            break;
                        int index = q.front();
                        q.pop();
                        if (min+1 == last)
                            min++;
                        ans[index] = ++min;
                    }
                }
                min = num - 1;
            }
        }
        else
        {
            q.push(i);
            ans.push_back(1e6);
        }
        last = num;
    }

    for (int i = 0; i < n; i++)
        cout << ans[i] << " ";
    cout << "\n";
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    vector<int> ans{};
    queue<int> q{};
    int last = -1, min = -1;

    for (int i = 0; i < n; i++)
    {
        int num;
        cin>>num;
        if (num > i+2)
        {
            cout << "-1\n";
            return 0;
        }

        if (last != -1)
        {
            if (last == num)
            {
                q.push(i);
                ans.push_back(1e6);
                continue;
            }
            else
            {
                ans.push_back(last);

                if (num > min + 1)
                {
                    for (int j = 1; j < num-last; j++)
                    {
                        int index = q.front();
                        q.pop();
                        ans[index] = last+j;
                        min = last+j;
                    }
                }
            }
        }
        else
        {
            min = (num == 0 ? 1 : 0);
            ans.push_back(min);
        }
        last = num;
    }

    for (int i = 0; i < n; i++)
        cout << ans[i] << " ";
    cout << "\n";
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    vector<int> ans{};
    queue<int> q{};
    int last = -1, min = -1;

    for (int i = 0; i < n; i++)
    {
        int num;
        cin>>num;
        if (num > i+1)
        {
            cout << "-1\n";
            return 0;
        }

        if (last != -1)
        {
            if (last == num)
            {
                q.push(i);
                ans.push_back(ans.back());
                continue;
            }
            else
            {
                ans.push_back(last);

                if (num > min + 1)
                {
                    for (int j = 1; j < num-last; j++)
                    {
                        if (q.size() == 0)
                            break;
                        int index = q.front();
                        q.pop();
                        ans[index] = max(last, min)+j;
                    }
                    min = num;
                }
            }
        }
        else
        {
            min = (num == 0 ? 1 : 0);
            ans.push_back(min);
        }
        last = num;
    }

    for (int i = 0; i < n; i++)
        cout << ans[i] << " ";
    cout << "\n";
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    vector<int> ans{};
    queue<int> q{};
    int last = -1, min = -1;

    if (n == 1)
    {
        int i;
        cin>>i;
        if (i != 1 && i != 0)
            cout << "-1\n";
        else
            cout << (i == 0 ? 1 : 0) << "\n";
        return 0;
    }

    for (int i = 0; i < n; i++)
    {
        int num;
        cin>>num;
        if (num > i+1)
        {
            cout << "-1\n";
            return 0;
        }

        if (last != -1)
        {
            if (last == num)
            {
                q.push(i);
                ans.push_back(1e6);
                continue;
            }
            else
            {
                ans.push_back(last);

                if (num > min + 2)
                {
                    for (int j = 0; j < num-last && min < num - 1; j++)
                    {
                        if (q.size() == 0)
                            break;
                        int index = q.front();
                        q.pop();
                        if (min+1 == last)
                            min++;
                        ans[index] = ++min;
                    }
                }
                min = num - 1;
            }
        }
        else
        {
            q.push(i);
            ans.push_back(1e6);
        }
        last = num;
    }

    for (int i = 0; i < n; i++)
        cout << ans[i] << " ";
    cout << "\n";
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    vector<int> ans{};
    queue<int> q{};
    set<int> available{};
    for (int i = 0; i < n; i++)
        available.emplace(i);

    int last = -1;
    cin>>last;
    if (last == 1)
    {
        ans.push_back(0);
        available.erase(0);
    }
    else
    {
        ans.push_back(1e6);
        q.push(0);
    }

    for (int i = 1; i < n; i++)
    {
        int num;
        cin>>num;

        if (num > i+1)
        {
            cout << "-1\n";
            return 0;
        }

        if (last != num)
        {
            available.erase(last);
            while (*available.begin() <= num-1)
            {
                if (q.size() == 0)
                    break;
                int index = q.front();
                q.pop();
                ans[index] = *available.begin();
                available.erase(available.begin());
            }
            ans.push_back(last);
        }

        while (ans.size() < i+1)
        {
            ans.push_back(1e6);
            q.push(ans.size()-1);
        }

        last = num;
    }

    for (int i = 0; i < n; i++)
        cout << ans[i] << " ";
    cout << "\n";
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    vector<int> ans{};
    queue<int> q{};
    int last = -1, min = -1;

    for (int i = 0; i < n; i++)
    {
        int num;
        cin>>num;
        if (num > i+1)
        {
            cout << "-1\n";
            return 0;
        }

        if (last != -1)
        {
            if (last == num)
            {
                q.push(i);
                ans.push_back(1e6);
                continue;
            }
            else
            {
                ans.push_back(last);

                if (num > min + 1)
                {
                    for (int j = 1; j < num-last; j++)
                    {
                        if (q.size() == 0)
                            break;
                        int index = q.front();
                        q.pop();
                        ans[index] = max(last, min)+j;
                    }
                    min = num;
                }
            }
        }
        else
        {
            min = (num == 0 ? 1 : 0);
            ans.push_back(min);
        }
        last = num;
    }

    for (int i = 0; i < n; i++)
        cout << ans[i] << " ";
    cout << "\n";
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    vector<int> ans{};
    queue<int> q{};
    int last = -1, fill = 0;

    for (int i = 0; i < n; i++)
    {
        int num;
        cin>>num;
        if (num > i+1)
        {
            cout << "-1\n";
            return 0;
        }

        if (last != -1)
        {
            if (last == num)
            {
                q.push(i);
                ans.push_back(1e6);
                continue;
            }
            else
            {
                ans.push_back(last);
                fill = last;

                while (num > fill+1)
                {
                    if (q.size() == 0)
                        break;
                    int index = q.front();
                    q.pop();
                    ans[index] = ++fill;
                }
            }
        }
        else
        {
            if (num == 1)
                ans.push_back(0);
            else
            {
                q.push(i);
                ans.push_back(1e6);
            }
        }
        last = num;
    }

    for (int i = 0; i < n; i++)
        cout << ans[i] << " ";
    cout << "\n";
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    vector<int> ans{};
    queue<int> q{};
    int last = -1, min = -1;

    for (int i = 0; i < n; i++)
    {
        int num;
        cin>>num;
        if (num > i+1)
        {
            cout << "-1\n";
            return 0;
        }

        if (last != -1)
        {
            if (last == num)
            {
                q.push(i);
                ans.push_back(1e6);
                continue;
            }
            else
            {
                ans.push_back(last);

                if (num > min + 2)
                {
                    for (int j = 0; j < num-last; j++)
                    {
                        if (q.size() == 0)
                            break;
                        int index = q.front();
                        q.pop();
                        if (min+1 == last)
                            min++;
                        ans[index] = ++min;
                    }
                }
                min = num - 1;
            }
        }
        else
        {
            q.push(i);
            ans.push_back(1e6);
        }
        last = num;
    }

    for (int i = 0; i < n; i++)
        cout << ans[i] << " ";
    cout << "\n";
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    vector<int> ans{};
    queue<int> q{};
    int last = -1, fill = -1;
    q.push(0);

    for (int i = 0; i < n; i++)
    {
        int num;
        cin>>num;
        if (num > i+1)
        {
            cout << "-1\n";
            return 0;
        }

        ans.push_back(last == -1 || last == num ? 1e6 : last);
        if (last == num)
            q.push(i);
        fill = max(last, fill);

        while (num > fill+1)
        {
            if (q.size() == 0)
                break;
            int index = q.front();
            q.pop();
            ans[index] = ++fill;
        }
        last = num;
    }

    for (int i = 0; i < n; i++)
        cout << ans[i] << " ";
    cout << "\n";
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    vector<int> ans{};
    queue<int> q{};
    int last = -1, min = -1;

    for (int i = 0; i < n; i++)
    {
        int num;
        cin>>num;
        if (num > i+1)
        {
            cout << "-1\n";
            return 0;
        }

        if (last != -1)
        {
            if (last == num)
            {
                q.push(i);
                ans.push_back(1e6);
                continue;
            }
            else
            {
                ans.push_back(last);

                if (num > min + 2)
                {
                    for (int j = 0; j < num-last && min < num - 1; j++)
                    {
                        if (q.size() == 0)
                            break;
                        int index = q.front();
                        q.pop();
                        if (min+1 == last)
                            min++;
                        ans[index] = ++min;
                    }
                }
                min = num - 1;
            }
        }
        else
        {
            q.push(i);
            ans.push_back(1e6);
        }
        last = num;
    }

    for (int i = 0; i < n; i++)
        cout << ans[i] << " ";
    cout << "\n";
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    vector<int> ans{};
    queue<int> q{};
    int last = -1;

    for (int i = 0; i < n; i++)
    {
        int num;
        cin>>num;
        if (num > i+2)
        {
            cout << "-1\n";
            return 0;
        }

        if (last != -1)
        {
            if (last == num)
            {
                q.push(i);
                ans.push_back(1e6);
                continue;
            }
            else
            {
                ans.push_back(last);

                for (int j = 1; j < num-last; j++)
                {
                    int index = q.front();
                    q.pop();
                    ans[index] = last+j;
                }
            }
        }
        else ans.push_back(num == 0 ? 1 : 0);
        last = num;
    }

    for (int i = 0; i < n; i++)
        cout << ans[i] << " ";
    cout << "\n";
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    vector<int> ans{};
    queue<int> q{};
    int last = -1;

    for (int i = 0; i < n; i++)
    {
        int num;
        cin>>num;
        if (num > i+2)
        {
            cout << "-1\n";
            return 0;
        }

        if (last != -1)
        {
            if (last == num)
            {
                q.push(i);
                ans.push_back(1e9);
                continue;
            }
            else
            {
                ans.push_back(last);

                for (int j = 1; j < num-last; j++)
                {
                    int index = q.front();
                    q.pop();
                    ans[index] = last+j;
                }
            }
        }
        else ans.push_back(num == 0 ? 1 : 0);
        last = num;
    }

    for (int i = 0; i < n; i++)
        cout << ans[i] << " ";
    cout << "\n";
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    vector<int> ans{};
    queue<int> q{};
    int last = -1, min = -1;

    for (int i = 0; i < n; i++)
    {
        int num;
        cin>>num;
        if (num > i+2)
        {
            cout << "-1\n";
            return 0;
        }

        if (last != -1)
        {
            if (last == num)
            {
                q.push(i);
                ans.push_back(1e6);
                continue;
            }
            else
            {
                ans.push_back(last);

                if (num > min + 1)
                {
                    for (int j = 1; j < num-last; j++)
                    {
                        if (q.size() == 0)
                            break;
                        int index = q.front();
                        q.pop();
                        ans[index] = last+j;
                        min = last+j;
                    }
                }
            }
        }
        else
        {
            min = (num == 0 ? 1 : 0);
            ans.push_back(min);
        }
        last = num;
    }

    for (int i = 0; i < n; i++)
        cout << ans[i] << " ";
    cout << "\n";
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    vector<int> ans{};
    queue<int> q{};
    int last = -1, fill = 0;

    for (int i = 0; i < n; i++)
    {
        int num;
        cin>>num;
        if (num > i+1)
        {
            cout << "-1\n";
            return 0;
        }

        if (last != -1)
        {
            if (last == num)
            {
                q.push(i);
                ans.push_back(1e6);
                continue;
            }
            else
            {
                ans.push_back(last);
                fill = last;

                while (num > fill+1)
                {
                    if (q.size() == 0)
                        break;
                    int index = q.front();
                    q.pop();
                    ans[index] = ++fill;
                }
            }
        }
        else
        {
            q.push(i);
            ans.push_back(1e6);
        }
        last = num;
    }

    if (last == 1)
    {
        while (q.size())
        {
            int index = q.front();
            q.pop();
            ans[index] = 0;
        }
    }

    for (int i = 0; i < n; i++)
        cout << ans[i] << " ";
    cout << "\n";
}


#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>

#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
template <class T> using Tree=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> using oset=tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
#define sz(x) (long long)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define rall(x) x.rbegin(), x.rend()
#define rall(x) x.rbegin(), x.rend()
#define lb lower_bound
#define ub upper_bound
#define google(x) cout<<"CASE #"<<x<<": ";
#define all(x) x.begin(), x.end()
#define eb emplace_back
//benq template
using str=string;
#define ts to_string
str ts(char c){return str(1,c);}str ts(bool b){return b?"true":"false";}str ts(const char* s){return (str)s;}str ts(str s){return s;}
template<class A> str ts(complex<A> c){stringstream ss;ss<<c;return ss.str();}
str ts(vector<bool> v){str res="{";for(int i=0;i<v.size();i++){res+=char('0'+v[i]);res+="}";}return res;}
template<size_t SZ> str ts(bitset<SZ> b){str res = "";for(int i=0;i<b.size();i++){res+=char('0'+b[i]);}return res;}
template<class A, class B> str ts(pair<A,B> p);
template<class T> str ts(T v){bool fst=1;str res="{";for(const auto& x: v){if(!fst){res+=", ";}fst=0;res+=ts(x);}res+="}";return res;}
template<class A, class B> str ts(pair<A,B> p){return "("+ts(p.f)+", "+ts(p.s)+")";}
void DBG(){cerr<<"]"<<endl;}
template<class H, class... T> void DBG(H h, T... t){cerr<<ts(h);if(sizeof...(t)){cerr<<", ";}DBG(t...);}
#ifdef X
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
int main(){//fastio
	//read data
	clock_t tttt=clock();
    ll n;
    cin>>n;
    vl a(n);
    bitset<(int)1e6+1> used;
    for(int i=0;i<n;i++){
        cin>>a[i];
        used[a[i]]=true;
    }
    vl b;
    ll cur = 0;
    if(a[0]>1){
        cout<<"-1\n";
        return 0;
    }
    if(a[0]==0){
        /* cout<<"1 "; */
        /* b.pb(1); */
        /* used[1]=true; */
        /* cur=0; */
        cur = 1;
        while(used[cur]){
            cur++;
        }
        b.pb(cur);
        used[cur]=true;
    }
    else if(a[0]==1){
        /* cout<<"0 "; */
        b.pb(0);
        used[0]=true;
        cur=1;
    }
    for(int i=1;i<n;i++){
        if(a[i]==a[i-1]){
            while(used[cur] and cur <=(int)1e6){
                cur++;
            }
            if(cur==(int)1e6){
                cout<<"-1\n";
            }
            used[cur]=true;
            b.pb(cur);
        }
        else{
            if(cur < a[i-1]-1){
                cout<<"-1\n";
                return 0;
            }
            b.pb(a[i-1]);
        }
    }
    for(auto i: b){
        cout<<i<<" ";
    }
	tttt = clock()-tttt;
	cerr<<"Time Elapsed : "<<((double)tttt)/CLOCKS_PER_SEC<<'\n';
    return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>

#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
template <class T> using Tree=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> using oset=tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
#define sz(x) (long long)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define rall(x) x.rbegin(), x.rend()
#define rall(x) x.rbegin(), x.rend()
#define lb lower_bound
#define ub upper_bound
#define google(x) cout<<"CASE #"<<x<<": ";
#define all(x) x.begin(), x.end()
#define eb emplace_back
//benq template
using str=string;
#define ts to_string
str ts(char c){return str(1,c);}str ts(bool b){return b?"true":"false";}str ts(const char* s){return (str)s;}str ts(str s){return s;}
template<class A> str ts(complex<A> c){stringstream ss;ss<<c;return ss.str();}
str ts(vector<bool> v){str res="{";for(int i=0;i<v.size();i++){res+=char('0'+v[i]);res+="}";}return res;}
template<size_t SZ> str ts(bitset<SZ> b){str res = "";for(int i=0;i<b.size();i++){res+=char('0'+b[i]);}return res;}
template<class A, class B> str ts(pair<A,B> p);
template<class T> str ts(T v){bool fst=1;str res="{";for(const auto& x: v){if(!fst){res+=", ";}fst=0;res+=ts(x);}res+="}";return res;}
template<class A, class B> str ts(pair<A,B> p){return "("+ts(p.f)+", "+ts(p.s)+")";}
void DBG(){cerr<<"]"<<endl;}
template<class H, class... T> void DBG(H h, T... t){cerr<<ts(h);if(sizeof...(t)){cerr<<", ";}DBG(t...);}
#ifdef X
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
int main(){//fastio
	//read data
	clock_t tttt=clock();
    ll n;
    cin>>n;
    vl a(n);
    bitset<(int)1e6+1> used;
    for(int i=0;i<n;i++){
        cin>>a[i];
        used[a[i]]=true;
    }
    vl b;
    ll cur = 0;
    if(a[0]>1){
        cout<<"-1\n";
        return 0;
    }
    if(a[0]==0){
        /* cout<<"1 "; */
        /* b.pb(1); */
        /* used[1]=true; */
        /* cur=0; */
        cur = 1;
        while(used[cur]){
            cur++;
        }
        b.pb(cur);
        used[cur]=true;
    }
    else if(a[0]==1){
        /* cout<<"0 "; */
        b.pb(0);
        used[0]=true;
        cur=1;
    }
    for(int i=1;i<n;i++){
        if(a[i]==a[i-1]){
            while(used[cur] and cur <=(int)1e6){
                cur++;
            }
            if(cur==(int)1e6){
                cout<<"-1\n";
            }
            used[cur]=true;
            b.pb(cur);
        }
        else{

/*             if(cur < a[i-1]-1){ */
/*                 cout<<"-1\n"; */
/*                 return 0; */
/*             } */

            b.pb(a[i-1]);
        }
    }
    /* for(auto i: b){ */
        /* cout<<i<<" "; */
    /* } */
    multiset<int> cur1;
    for(int i=0;i<=(int)1e6;i++){
        cur1.insert(i);
         }
    for(int i=0;i<sz(b);i++){
        if(cur1.count(b[i])){
            cur1.erase(cur1.find(b[i]));
        }
        if(*cur1.begin() != a[i]){
            cout<<"-1\n";
            return 0;
        }
    }
    for(auto i: b){
        cout<<i<<" ";
    }
    cout<<"\n";
	tttt = clock()-tttt;
	cerr<<"Time Elapsed : "<<((double)tttt)/CLOCKS_PER_SEC<<'\n';
    return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>

#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
template <class T> using Tree=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> using oset=tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
#define sz(x) (long long)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define rall(x) x.rbegin(), x.rend()
#define rall(x) x.rbegin(), x.rend()
#define lb lower_bound
#define ub upper_bound
#define google(x) cout<<"CASE #"<<x<<": ";
#define all(x) x.begin(), x.end()
#define eb emplace_back
//benq template
using str=string;
#define ts to_string
str ts(char c){return str(1,c);}str ts(bool b){return b?"true":"false";}str ts(const char* s){return (str)s;}str ts(str s){return s;}
template<class A> str ts(complex<A> c){stringstream ss;ss<<c;return ss.str();}
str ts(vector<bool> v){str res="{";for(int i=0;i<v.size();i++){res+=char('0'+v[i]);res+="}";}return res;}
template<size_t SZ> str ts(bitset<SZ> b){str res = "";for(int i=0;i<b.size();i++){res+=char('0'+b[i]);}return res;}
template<class A, class B> str ts(pair<A,B> p);
template<class T> str ts(T v){bool fst=1;str res="{";for(const auto& x: v){if(!fst){res+=", ";}fst=0;res+=ts(x);}res+="}";return res;}
template<class A, class B> str ts(pair<A,B> p){return "("+ts(p.f)+", "+ts(p.s)+")";}
void DBG(){cerr<<"]"<<endl;}
template<class H, class... T> void DBG(H h, T... t){cerr<<ts(h);if(sizeof...(t)){cerr<<", ";}DBG(t...);}
#ifdef X
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
int main(){//fastio
	//read data
	clock_t tttt=clock();
    ll n;
    cin >> n;
    vl a(n);
    vl taken((int)1e6+1, 0);
    for(auto &i: a){

        cin>>i;
        taken[i]++;
    }
    vector<ll> ans;
    set<ll> cur;
    for(int i=0;i<=(int)1e6;i++){
        if(!taken[i])
        cur.insert(i);
    }
    ans.assign(n+1, -1);
    for(int i=0;i<n;i++){
        auto loc = cur.lower_bound(a[i]);
        if(loc!=cur.begin()){loc--;}
        else{
            loc = cur.upper_bound(a[i]);
            if(loc!=cur.end()){

            }
        }
        /* cout<<"NANI "<<*loc<<"\n"; */
        ans[i]=*loc;
        cur.insert(a[i]);
        /* cur.erase(cur.find(loc)); */

        cur.erase(cur.find(*loc));

    }
    set<ll> cur1;
    for(int i=0;i<=(int)1e6;i++){
        cur1.insert(i);
    }
    /* for(int i=0;i<n;i++){ */
        /* cout<<ans[i]<<" "; */
    /* } */
    /* cout<<"\n"; */
    for(int i=0;i<n;i++){
        if(cur1.count(ans[i])){
            cur1.erase(cur1.find(ans[i]));
        }
        if(*cur1.begin()!=a[i]){
            cout<<"-1\n";
            return 0;
        }
    }
    for(int i=0;i<n;i++){
        cout<<ans[i]<<" ";
    }
	tttt = clock()-tttt;
	cerr<<"Time Elapsed : "<<((double)tttt)/CLOCKS_PER_SEC<<'\n';
    return 0;
}