#include <bits/stdc++.h>
using namespace std;
int n;
int a[200010];
int prv[200010];
int f[200010][10];
void FillAll(int l, int r, int x, int y) {
  for (int i = x, j = l; i <= y; i++) {
    int ci = (r - j + 1) / (y - i + 1);
    ci = max(ci, 2);
    ci = min(ci, 5);
    for (int jj = j; jj < j + ci; jj++) a[jj] = i;
    j += ci;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
  }
  for (int i = 1; i <= n; i++) prv[i] = a[i - 1] ? i - 1 : prv[i - 1];
  memset(f, -1, sizeof f);
  f[0][5] = 0;
  int last = 0;
  for (int i = 1; i <= n; i++)
    if (a[i]) {
      last = i;
      int j = prv[i];
      int space = i - j - 1;
      if (a[i] > a[j]) {
        for (int ki = 0; ki < min(5, space + 1); ki++)
          for (int kj1 = 1; kj1 <= 5 && f[i][ki + 1] == -1; kj1++)
            if (f[j][kj1] >= 0) {
              for (int kj2 = max(0, 2 - kj1); kj2 <= min(space - ki, 5 - kj1);
                   kj2++) {
                int least = kj2 + 2 * (a[i] - a[j] - 1) + ki;
                int most = kj2 + 5 * (a[i] - a[j] - 1) + ki;
                if (least <= space && space <= most) {
                  f[i][ki + 1] = kj2;
                  break;
                }
              }
            }
      }
      if (a[i] == a[j]) {
        int ki = space + 1;
        for (int kj = 1; kj <= 5 - ki; kj++)
          if (f[j][kj] >= 0) f[i][ki + kj] = 0;
      }
      if (a[i] < a[j]) {
        printf("-1");
        return 0;
      }
    }
  if (last) {
    int had = last == n - 1;
    for (int i = last; i; i = prv[i]) {
      int j = prv[i];
      if (a[i] != a[j]) {
        int lbound = max(1, 2 - had);
        int rbound = 5 - had;
        if (i == last) {
          lbound = 1 + (last == n);
          rbound = 5 - (last == n - 1);
        }
        bool isRet = 0;
        for (int ki = rbound; ki >= lbound; ki--)
          if (f[i][ki] >= 0) {
            for (int k = i - ki + 1; k <= i; k++) a[k] = a[i];
            for (int k = j + 1; k <= j + f[i][ki]; k++) a[k] = a[j];
            FillAll(j + f[i][ki] + 1, i - ki, a[j] + 1, a[i] - 1);
            had = f[i][ki];
            isRet = 1;
            break;
          }
        if (!isRet) {
          printf("-1");
          return 0;
        }
      } else {
        for (int k = j + 1; k < i; k++) a[k] = a[i];
        had += i - j;
      }
    }
    if (a[last] != a[last - 1]) {
      a[last + 1] = a[last];
      last++;
    }
    if (last > n) {
      printf("-1");
      return 0;
    }
  }
  for (int i = last + 1; i <= n; i++)
    if (i == 1 || a[i - 1] == a[i - 2])
      a[i] = a[i - 1] + 1;
    else
      a[i] = a[i - 1];
  if (a[n] != a[n - 1]) a[n] = a[n - 1];
  printf("%d\n", a[n]);
  for (int i = 1; i <= n; i++) printf("%d ", a[i]);
  return 0;
}
