#include <bits/stdc++.h>
using namespace std;
bool ok[200010][7];
int n, v[200010], pre[200010];
void read() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", v + i);
}
void print(int n, int m) {
  if (n == 1) {
    printf("1 ");
    return;
  }
  int p = pre[n];
  if (v[p] == v[n]) {
    for (int a = 1; a + n - p <= 5; ++a)
      if (ok[p][a]) {
        print(p, a);
        for (int j = p + 1; j <= n; ++j) printf("%d ", v[n]);
        return;
      }
  } else {
    for (int a = 1; a <= 5; ++a)
      if (ok[p][a])
        for (int b = max(0, 2 - a); b <= 5 - a; ++b) {
          int t = n - b - m - p;
          if (t < 0 || (v[n] - v[p] - 1) * 2 > t || (v[n] - v[p] - 1) * 5 < t)
            continue;
          print(p, a);
          for (int i = 1; i <= b; ++i) printf("%d ", v[p]);
          for (int i = v[p] + 1; i < v[n]; ++i) {
            for (int j = 1; j <= 5; ++j) {
              --t;
              printf("%d ", i);
              if (j >= 2 && (v[n] - i - 1) * 2 <= t && (v[n] - i - 1) * 5 >= t)
                break;
            }
          }
          for (int i = 1; i <= m; ++i) printf("%d ", v[n]);
          return;
        }
  }
}
void print() {
  if (v[1] > 1) {
    printf("-1\n");
    return;
  }
  v[1] = 1;
  ok[1][1] = true;
  int last = 1;
  for (int i = 2; i <= n; ++i)
    if (v[i]) {
      if (v[i] == v[last]) {
        for (int a = 1; a + i - last <= 5; ++a)
          if (ok[last][a]) ok[i][a + i - last] = true;
      } else {
        for (int c = 1; c <= 5; ++c)
          for (int a = 1; a <= 5 && !ok[i][c]; ++a)
            if (ok[last][a])
              for (int b = max(0, 2 - a); b <= 5 - a; ++b) {
                int t = i - last - b - c;
                if (t < 0) continue;
                if ((v[i] - v[last] - 1) * 2 <= t &&
                    (v[i] - v[last] - 1) * 5 >= t)
                  ok[i][c] = true;
              }
      }
      pre[i] = last, last = i;
      if (count(ok[i] + 1, ok[i] + 6, true) == 0) {
        printf("-1\n");
        return;
      }
    }
  if (last == n && count(ok[n] + 2, ok[n] + 6, true) == 0) {
    printf("-1\n");
    return;
  }
  for (int i = 5; i >= 1; --i)
    if (ok[last][i]) {
      int j = last, cnt;
      if (i == 1) ++j, v[j] = v[j - 1];
      for (j = j + 1, cnt = 1; j <= n; ++j) {
        if (j == n)
          v[j] = v[j - 1], ++cnt;
        else {
          if (cnt == 1)
            v[j] = v[j - 1] + 1, ++cnt;
          else
            v[j] = v[j - 1], cnt = 1;
        }
      }
      printf("%d\n", v[n]);
      print(last, i);
      for (j = last + 1; j <= n; ++j) printf("%d ", v[j]);
      return;
    }
}
int main() {
  read();
  print();
  return 0;
}
