#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   const int maxm = 1e3 + 5;   const int mod = 1e9 + 7;   const int inf = 0x3f3f3f3f;   int a[maxn], ans[maxn], l[maxn][6], r[maxn][6];   inline void solve() {     int n;     scanf( %d , &n);     for (int i = 1; i < n + 1; i++) scanf( %d , &a[i]);     memset(l, -1, sizeof l);     memset(r, -1, sizeof r);     if (a[1] > 1) {       puts( -1 );       exit(0);     }     l[1][1] = r[1][1] = 1;     for (int i = 2; i < n + 1; i++) {       for (int j = 2; j < 5 + 1; j++) {         if (l[i - 1][j - 1] != -1) {           l[i][j] = l[i - 1][j - 1];           r[i][j] = r[i - 1][j - 1];         }       }       for (int j = 2; j < 5 + 1; j++) {         if (l[i - 1][j] != -1) {           if (l[i][1] == -1) l[i][1] = inf;           l[i][1] = min(l[i][1], l[i - 1][j] + 1);           r[i][1] = max(r[i][1], r[i - 1][j] + 1);         }       }       if (a[i]) {         for (int j = 1; j < 5 + 1; j++) {           if (l[i][j] != -1) {             if (l[i][j] <= a[i] && a[i] <= r[i][j])               l[i][j] = r[i][j] = a[i];             else               l[i][j] = r[i][j] = -1;           } else             r[i][j] = -1;         }       }       bool ok = 0;       for (int j = 1; j < 5 + 1; j++) {         if (l[i][j] <= r[i][j] && l[i][j] != -1) {           ok = 1;           break;         }       }       if (!ok) {         puts( -1 );         exit(0);       }     }     int up = 0, j = 2;     for (int i = 2; i < 5 + 1; i++) {       if (l[n][i] <= r[n][i] && l[n][i] != -1) {         if (r[n][i] > up) {           up = r[n][i];           j = i;         }       }     }     if (up == 0) {       puts( -1 );       exit(0);     }     printf( %d n , up);     int m = n;     while (m) {       for (int i = m - j; i < m + 1; i++) ans[i] = up;       m -= j;       up--;       for (int i = 2; i < 5 + 1; i++) {         if (l[m][i] <= up && up <= r[m][i]) j = i;       }     }     for (int i = 1; i < n + 1; i++) {       if (i == 1)         printf( %d , ans[i]);       else         printf(  %d , ans[i]);     }     puts(  );   }   int main() {     solve();     return 0;   }   