#include <bits/stdc++.h>
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;
}
const int N = 200010;
int a[N], ox[N], oy[N], ans[N];
int n, m;
int dfs(int k, int l1, int l2) {
  setmin(l2, ox[k]);
  int r1 = std::max(l1 + 1, oy[k]), r2 = l2 + 4;
  if (l1 > l2 || r1 > r2) return -1;
  int p = dfs(k + 1, r1 + 1, r2 + 1) - 1;
  if (p > 0) {
    int q = std::max(l1, p - 4);
    for (int i = int(q); i <= int(p); ++i) ans[i] = k;
    return q;
  }
  return (l1 <= n + 1 && l2 >= n + 1 && k > m ? n + 1 : -1);
}
bool solve() {
  std::fill(ox, ox + N, n + 1);
  std::fill(oy, oy + N, -1);
  m = 0;
  for (int i = int(1); i <= int(n); ++i)
    if (a[i] > 0) {
      setmin(ox[a[i]], i);
      setmax(oy[a[i]], i);
      setmax(m, a[i]);
    }
  return dfs(1, 1, 1) > 0;
}
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;
}
