#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200010;
int a[MAXN];
int b[MAXN];
int dp[MAXN][6][6];
int prevV[MAXN][6][6];
int n;
int main() {
  while (cin >> n) {
    memset(dp, 0, sizeof(dp));
    memset(prevV, 0, sizeof(prevV));
    for (int i = 0; i < n; i++) cin >> a[i], b[i] = a[i];
    if (a[0] != 0 && a[0] != 1) {
      cout << -1 << endl;
      continue;
    }
    dp[0][2][0] = true;
    dp[0][3][0] = true;
    dp[0][4][0] = true;
    dp[0][5][0] = true;
    a[0] = 1;
    b[0] = 1;
    int prevI = 0;
    for (int i = 1; i < n; i++) {
      if (a[i] != 0) {
        int dist = i - prevI;
        for (int j = 2; j <= 5; j++) {
          for (int k = 0; k < j; k++) {
            if (a[i] == a[prevI]) {
              if (k - dist >= 0 && dp[prevI][j][k - dist]) {
                prevV[i][j][k] = j * 100 + k - dist;
                dp[i][j][k] = true;
              }
            } else if (a[i] > a[prevI]) {
              for (int r = 2; r <= 5 && !dp[i][j][k]; r++) {
                for (int c = 0; c < r && !dp[i][j][k]; c++) {
                  if (dp[prevI][r][c]) {
                    int startI = prevI + r - c;
                    int startV = a[prevI] + 1;
                    int endI = i - k - 1;
                    int endV = a[i] - 1;
                    if (endI - startI + 1 >= 2 * (endV - startV + 1) &&
                        endI - startI + 1 <= 5 * (endV - startV + 1)) {
                      prevV[i][j][k] = r * 100 + c;
                      dp[i][j][k] = true;
                    }
                  }
                }
              }
            }
          }
        }
        prevI = i;
      }
    }
    int next = -1;
    for (int i = n - 1; i >= 0; i--) {
      if (b[i] != 0) {
        if (next == -1) {
          for (int kk = 0; kk < 5; kk++) {
            for (int j = 2; j <= 5; j++) {
              int k = j - 1 - kk;
              if (k < 0) continue;
              if (dp[i][j][k]) {
                int left = n - i - j + k;
                if (left < 0 || left == 1)
                  dp[i][j][k] = false;
                else {
                  for (int r = i - k; r < n; r++) {
                    if (r < i - k + j)
                      a[r] = a[i];
                    else {
                      if (n - r >= 2) {
                        a[r] = a[r + 1] = a[r - 1] + 1;
                        r++;
                      } else {
                        a[r] = a[r - 1];
                      }
                    }
                  }
                  prevI = prevV[i][j][k];
                  goto OUT;
                }
              }
            }
          }
          cout << -1 << endl;
          goto END;
        } else {
          int j = prevI / 100;
          int k = prevI % 100;
          assert(dp[i][j][k]);
          for (int r = 0; r < j; r++) {
            assert(a[i - k + r] == 0 || a[i - k + r] == a[i]);
            a[i - k + r] = a[i];
          }
          int len = 0;
          while (i - k + j + len < n && a[i - k + j + len] == 0) len++;
          if (len != 0) {
            int num = a[i - k + j + len] - a[i] - 1;
            assert(len == 0 || num >= 1);
            int sz = len / num;
            int start = a[i] + 1;
            for (int r = 0; r < len; r++) {
              if ((sz + 1) * (len % num) > r) {
                a[i - k + j + r] = r / (sz + 1) + start;
              } else {
                a[i - k + j + r] = (r - (len % num)) / sz + start;
              }
            }
          }
          prevI = prevV[i][j][k];
        }
      OUT:;
        next = i;
      }
    }
    cout << a[n - 1] << endl;
    for (int i = 0; i < n; i++) {
      if (i) cout << " ";
      cout << a[i];
    }
    cout << endl;
  END:;
  }
}
