#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];
bool f[N][5];
int n;
bool fit(int i, int j, int ival, int jval, bool fill = false) {
  int num = jval - ival + 1;
  int spaces = j - i + 1;
  if (num == 0 && spaces == 0) return true;
  if (spaces >= num * 2 && spaces <= num * 5) {
    if (fill) {
      int avg = spaces / num;
      int res = spaces % num;
      for (int x = int(0); x <= int((res)-1); ++x) {
        for (int y = int(0); y <= int((avg + 1) - 1); ++y) ans[i++] = ival;
        ++ival;
      }
      for (int x = int(0); x <= int((num - res) - 1); ++x) {
        for (int y = int(0); y <= int((avg)-1); ++y) ans[i++] = ival;
        ++ival;
      }
      assert(i == j + 1);
      assert(ival == jval + 1);
    }
    return true;
  } else {
    return false;
  }
}
void put(int i, int j, int val) {
  for (int k = int(i); k <= int(j); ++k) ans[k] = val;
}
bool check_f(int i, int k, bool fill = false);
bool check(int i, int j, int jval, bool fill = false) {
  for (int k = int(0); k <= int((5) - 1); ++k)
    if (f[i][k]) {
      int l = max(i - k + 1, i), r = i - k + 4;
      for (int i2 = int(l); i2 <= int(min(r, j)); ++i2) {
        if (fit(i2 + 1, j, a[i] + 1, jval)) {
          if (fill) {
            assert(fit(i2 + 1, j, a[i] + 1, jval, true));
            put(i, i2, a[i]);
            assert(check_f(i, k, true));
          }
          return true;
        }
      }
    }
  return false;
}
bool check_f(int i, int k, bool fill) {
  if (i == 1 && k == 0) {
    ans[1] = 1;
    return true;
  }
  int p = pre[i];
  if (a[p] > a[i]) return false;
  if (a[p] == a[i]) {
    bool r = (i - k <= p && f[p][p - (i - k)]);
    if (r && fill) {
      put(p, i, a[i]);
      assert(check_f(p, p - (i - k), true));
    }
    return r;
  }
  bool r = (i - k > p && check(p, i - k - 1, a[i] - 1));
  if (r && fill) {
    put(i - k, i, a[i]);
    assert(check(p, i - k - 1, a[i] - 1, true));
  }
  return r;
}
bool solve() {
  if (a[1] > 0 && 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;
    }
  memset(f, false, sizeof(f));
  f[1][0] = true;
  for (int i = int(2); i <= int(n); ++i)
    if (a[i] > 0) {
      for (int k = int(0); k <= int((5) - 1); ++k) f[i][k] = check_f(i, k);
    }
  for (int v = int(100000); v >= int(1); --v) {
    if (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]);
  bool status = solve();
  if (status) {
    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;
}
