#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], ans[N];
pair<int, int> occ[N], p[N];
int n;
bool solve() {
  fill(occ, occ + N, make_pair(n + 1, -1));
  int maxval = 0;
  for (int i = int(1); i <= int(n); ++i)
    if (a[i] > 0) {
      setmin(occ[a[i]].first, i);
      setmax(occ[a[i]].second, i);
      setmax(maxval, a[i]);
    }
  int cur = 0;
  p[0] = make_pair(0, 0);
  while (1) {
    ++cur;
    int l1 = p[cur - 1].first + 1, l2 = p[cur - 1].second + 1;
    setmin(l2, occ[cur].first);
    if (l1 > l2) break;
    int r1 = l1 + 1, r2 = l2 + 4;
    setmax(r1, occ[cur].second);
    if (r1 > r2) break;
    p[cur] = make_pair(r1, r2);
  }
  --cur;
  while (p[cur].first > n) --cur;
  if (p[cur].second < n || cur < maxval) return false;
  int i = n;
  while (cur > 0) {
    if (occ[cur].second >= 0) assert(i >= occ[cur].second);
    int l1 = i - 4, l2 = i;
    if (occ[cur].first >= 0) setmin(l2, occ[cur].first);
    for (int j = int(l1); j <= int(l2); ++j)
      if (j - 1 >= p[cur - 1].first && j - 1 <= p[cur - 1].second) {
        l1 = j;
        break;
      }
    for (int j = int(l1); j <= int(i); ++j) ans[j] = cur;
    --cur, i = l1 - 1;
  }
  assert(i == 0);
  return true;
}
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;
}
