#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int n;
int a[300000];
int b[300000][2];
int bi;
int d[300000][5];
int p[300000][5][2];
int dab[300000];
void path(int x, int y) {
  int i, j, k, l;
  if (x == 0 && y == 0) {
    return;
  }
  int su1, su2, start, end;
  su1 = a[p[x][y][0]] + 1;
  start = p[x][y][0] + p[x][y][1] + 1;
  su2 = a[x];
  end = x + y;
  if (y != 0) {
    for (i = x; i <= x + y; i++) dab[i] = a[x];
    su2 = su2 - 1;
    end = x;
    l = y;
  } else {
    for (i = x - 1; i <= x + y; i++) dab[i] = a[x];
    su2 = su2 - 1;
    end = x - 1;
    l = y + 1;
  }
  for (; l <= 4; l++) {
    dab[end] = a[x];
    end--;
    int length, gatsu;
    int flag = 0;
    length = end - start + 1, gatsu = su2 - su1 + 1;
    for (i = 2; i <= 4; i++) {
      int low, high;
      if (length >= gatsu * i && length <= gatsu * (i + 1)) {
        flag = 1;
        high = length - gatsu * i;
        low = gatsu - high;
        int xx = su1;
        for (j = 0; j < low; j++) {
          for (k = 0; k < i; k++) {
            dab[start + j * i + k] = xx;
          }
          xx++;
        }
        int xstart = start + low * i;
        for (j = 0; j < high; j++) {
          for (k = 0; k < i + 1; k++) {
            dab[xstart + j * (i + 1) + k] = xx;
          }
          xx++;
        }
      }
    }
    if (flag == 1) break;
  }
  path(p[x][y][0], p[x][y][1]);
}
int main() {
  int i, j, k;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i + 1]);
    if (a[i + 1] != 0) {
      b[bi][0] = a[i + 1];
      b[bi][1] = i + 1;
      bi++;
    }
  }
  d[0][0] = 1;
  int lastd = 0;
  for (i = 1; i <= n; i++) {
    if (!a[i]) continue;
    for (j = 0; j < 5; j++) {
      if (!d[lastd][j]) continue;
      int min;
      if (a[lastd] != a[i])
        min = lastd + j + (a[i] - a[lastd] - 1) * 2 + 1;
      else
        min = -1;
      int min2 = lastd + j + (a[i] - a[lastd]) * 2;
      int max = lastd + j + (a[i] - a[lastd]) * 5;
      for (k = 0; k < 5; k++) {
        if (i == 4 && k == 3) {
          i = i;
        }
        if (a[i + k] && a[i + k] != a[i]) break;
        if (i >= min && i + k >= min2 && i + k <= max) {
          d[i][k] = 1;
          p[i][k][0] = lastd;
          p[i][k][1] = j;
        }
      }
    }
    lastd = i;
  }
  int flag = 0;
  for (i = 0; i < 5; i++) {
    if (lastd + i > n) break;
    if (d[lastd][i] == 1) {
      flag = 1;
      break;
    }
  }
  if (flag == 0) {
    printf("-1");
    return 0;
  }
  if (lastd + i == n - 1) {
    if (i == 4) {
      printf("-1");
      return 0;
    }
    dab[lastd + i] = a[lastd];
    dab[lastd + i + 1] = a[lastd];
    path(lastd, i);
  } else {
    path(lastd, i);
    int xx = a[lastd];
    for (j = 0;; j++) {
      if (lastd + i + j * 2 + 2 > n) break;
      xx++;
      dab[lastd + i + j * 2 + 1] = xx;
      dab[lastd + i + j * 2 + 2] = xx;
    }
    if (dab[n] == 0) {
      dab[n] = xx;
    }
  }
  printf("%d\n", dab[n]);
  for (i = 1; i <= n; i++) printf("%d ", dab[i]);
  return 0;
}
