#include<bits/stdc++.h>
using namespace std;
#define inf 1e18
#define endl '\n'
#define int long long
typedef long long ll;
typedef pair<int,int> pii;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const int maxn=2e5+9;
int a[maxn];
void solve(){
int n;cin >> n;
for(int i=1;i<=n;i++){
cin >> a[i];
}
int l=0,r=0;//找左边和右边第一个出现的非零数
bool f1=false;
vector<pii> vt;
vector<int> ans(n+1);
for(int i=1;i<=n;i++){
if(!f1&&a[i]){
l=i;
f1=true;
}
if(a[i]){
r=i;
vt.push_back({i,a[i]});
ans[i]=a[i];
}
}
if(r==0){
for(int i=1;i<=n;i++) cout << i << " ";
cout << endl;
return;
}
//处理l左边的
for(int i=l-1;i>=1;i--){
ans[i]=ans[i+1]+1;
}
//处理r右边的
for(int i=r+1;i<=n;i++){
ans[i]=ans[i-1]+1;
}
//处理中间的
if(vt.size()>1){
int id=vt[0].first;
int val=vt[0].second;
for(int i=1;i<vt.size();i++){
auto [nowi,nv]=vt[i];
int zeros=nowi-id-1;
int t=abs(val-nv)-1;
if(t==-1) t=1;
if(zeros==0) continue;
if(zeros<t){
cout << -1 << endl;
return;
}
if((zeros-t)%2!=0){
cout << -1 << endl;
return;
}
//先添加必须的数
for(int j=id+1;j<=id+t;j++){
if(val>=nv){
ans[j]=ans[j-1]-1;
}else{
ans[j]=ans[j-1]+1;
}
}
//添加循环数
int f=1;
for(int j=id+t+1;j<nowi;j++){
ans[j]=max(nv,val)-1;
if(f){
ans[j]-=1;
f^=1;
}
}
id=nowi;
val=nv;
}
}
for(int i=1;i<=n;i++) cout << ans[i] << " ";
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int t=1;
//cin >> t;
while(t--){
solve();
}
return 0;
}
/*
15
0 0 5 0 0 2 0 0 0 4 0 0 5 0 0
*/