#include <bits/stdc++.h>
using namespace std;
template <class T>
bool setmax(T &_a, T _b) {
  if (_b > _a) {
    _a = _b;
    return true;
  }
  return false;
}
template <class T>
bool setmin(T &_a, T _b) {
  if (_b < _a) {
    _a = _b;
    return true;
  }
  return false;
}
template <class T>
T gcd(T _a, T _b) {
  return _b == 0 ? _a : gcd(_b, _a % _b);
}
const int N = 200010;
int a[N], pre[N], ans[N];
int n;
void put(int i, int j, int v) {
  for (int k = int(i); k <= int(j); ++k) ans[k] = v;
}
bool batch_put(int i, int j, int iv, int jv, bool to_fill = false) {
  int num = jv - iv + 1;
  int spaces = j - i + 1;
  if (spaces < num * 2 || spaces > num * 5) return false;
  if (to_fill) {
    for (int v = int(iv); v <= int(jv); ++v) {
      for (int z = int(0);
           z <= int((spaces / num + (v - iv < spaces % num ? 1 : 0)) - 1); ++z)
        ans[i++] = v;
    }
    assert(i == j + 1);
  }
  return true;
}
bool check(int i, int j, int jval, bool to_fill = false);
bool f(int i, int s, bool to_fill = false) {
  static pair<bool, bool> mem[N][5];
  static bool inited = false;
  if (!inited) {
    inited = true;
    memset(mem, false, sizeof(mem));
  }
  bool &r = mem[i][s].second;
  if (mem[i][s].first && !to_fill) return r;
  mem[i][s].first = true;
  if (i == 1) {
    r = (s == 0);
    if (to_fill) {
      ans[1] = 1;
    }
  } else {
    int p = pre[i];
    if (a[p] > a[i]) r = false;
    if (a[p] == a[i]) {
      r = (s >= i - p && f(p, s - (i - p), to_fill));
      if (to_fill) {
        put(p + 1, i, a[i]);
      }
    } else {
      r = (i - s > p && check(p, i - s - 1, a[i] - 1, to_fill));
      if (to_fill) {
        put(i - s, i, a[i]);
      }
    }
  }
  return r;
}
bool check(int i, int j, int jval, bool to_fill) {
  if (a[i] > jval) return false;
  for (int s = int(0); s <= int((5) - 1); ++s)
    if (f(i, s)) {
      int l = max(i, i - s + 1), r = min(j, i - s + 4);
      for (int i2 = int(l); i2 <= int(r); ++i2) {
        if (batch_put(i2 + 1, j, a[i] + 1, jval)) {
          if (to_fill) {
            assert(f(i, s, true));
            put(i, i2, a[i]);
            assert(batch_put(i2 + 1, j, a[i] + 1, jval, true));
          }
          return true;
        }
      }
    }
  return false;
}
bool solve() {
  if (a[1] > 1) return false;
  a[1] = 1;
  pre[1] = 0;
  int la = 1;
  for (int i = int(2); i <= int(n); ++i)
    if (a[i] > 0) pre[i] = la, la = i;
  for (int v = int(100000); v >= int(1); --v)
    if (check(la, n, v)) {
      check(la, n, v, true);
      return true;
    }
  return false;
}
int main() {
  scanf("%d", &n);
  for (int i = int(1); i <= int(n); ++i) scanf("%d", &a[i]);
  if (solve()) {
    printf("%d\n", ans[n]);
    for (int i = int(1); i <= int(n); ++i) printf("%d ", ans[i]);
    printf("\n");
  } else {
    printf("-1\n");
  }
  return 0;
}
