#include <bits/stdc++.h>
using namespace std;
int n, m;
inline int read() {
  char c;
  int res, flag = 0;
  while ((c = getchar()) > '9' || c < '0')
    if (c == '-') flag = 1;
  res = c - '0';
  while ((c = getchar()) >= '0' && c <= '9')
    res = (res << 3) + (res << 1) + c - '0';
  return flag ? -res : res;
}
const int N = 210000;
int a[N], Min[N], big, cnt[N], l[N], val[N];
inline void change() {
  int x;
  x = big;
  while (cnt[x] == 5) {
    if (a[l[x]] == x) {
      printf("-1");
      exit(0);
    }
    val[l[x]] = x - 1;
    l[x]++;
    --x;
  }
  if (!x) {
    printf("-1");
    exit(0);
  } else
    cnt[x]++;
}
int ccnt[N], cl[N], cval[N];
inline bool fget() {
  for (int i = 1; i <= big; ++i) ccnt[i] = cnt[i], cl[i] = l[i];
  for (int i = 1; i <= n; ++i) cval[i] = val[i];
  int x;
  x = big;
  while (cnt[x] < 2) {
    if (a[l[x] - 1] == x - 1) return 0;
    val[l[x] - 1] = x;
    cnt[x]++;
    cnt[x - 1]--;
    l[x]--;
    --x;
  }
  if (!x) return 0;
  return 1;
}
inline void reset() {
  for (int i = 1; i <= big; ++i) cnt[i] = ccnt[i], l[i] = cl[i];
  for (int i = 1; i <= n; ++i) val[i] = cval[i];
}
int main() {
  n = read();
  for (int i = 1; i <= n; ++i) a[i] = val[i] = read();
  if (a[1] != 1 && a[1] != 0) {
    printf("-1");
    return 0;
  }
  a[1] = val[1] = 1;
  big = 1;
  if (a[n])
    Min[n] = a[n];
  else
    Min[n] = 1e9;
  for (int i = n - 1; i >= 1; --i) {
    Min[i] = Min[i + 1];
    if (a[i]) Min[i] = min(Min[i], a[i]);
    if (a[i] > Min[i + 1]) {
      printf("-1");
      return 0;
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (a[i]) {
      if (a[i] > big) {
        if (cnt[big] < 2) {
          if (!fget()) {
            reset();
            cnt[big]--;
            val[i - 1] = big - 1;
            --big;
            if (cnt[big] == 5)
              change();
            else
              cnt[big]++;
          }
        }
        if (a[i] > big + 1) {
          printf("-1");
          return 0;
        }
        if (big != a[i]) l[a[i]] = i;
        big = a[i];
        if (cnt[big] == 5)
          change();
        else
          cnt[big]++;
      } else {
        if (cnt[big] == 5)
          change();
        else
          cnt[big]++;
      }
    } else {
      if (big < Min[i] && cnt[big] >= 2)
        big++, cnt[big] = 1, l[big] = i;
      else {
        if (cnt[big] == 5)
          change();
        else
          cnt[big]++;
      }
      val[i] = big;
    }
  }
  if (cnt[big] < 2) {
    if (a[n]) {
      printf("-1");
      return 0;
    }
    if (!fget()) {
      reset();
      val[n] = big - 1;
      --big;
      if (cnt[big] == 5) change();
    }
  }
  printf("%d\n", val[n]);
  for (int i = 1; i <= n; ++i) printf("%d ", val[i]);
}
