#include <bits/stdc++.h>
using namespace std;
int n, a[300000], cnt[300000];
pair<int, int> m[300000], M[300000];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  if (a[1] > 1) {
    printf("-1\n");
    return 0;
  }
  m[1] = M[1] = make_pair(1, 1);
  bool ok = true;
  for (int i = 2; i <= n && ok; i++) {
    if (m[i - 1].second == 5) {
      m[i].first = m[i - 1].first + 1;
      m[i].second = 1;
    } else {
      m[i].first = m[i - 1].first;
      m[i].second = m[i - 1].second + 1;
    }
    if (M[i - 1].second >= 2) {
      M[i].first = M[i - 1].first + 1;
      M[i].second = 1;
    } else {
      M[i].first = M[i - 1].first;
      M[i].second = M[i - 1].second + 1;
    }
    if (a[i]) {
      if (a[i] < m[i].first || a[i] > M[i].first)
        ok = false;
      else {
        m[i] = max(m[i], make_pair(a[i], 1));
        M[i] = min(M[i], make_pair(a[i], 5));
      }
    }
  }
  if (!ok) {
    printf("-1\n");
    return 0;
  }
  pair<int, int> ans = M[n];
  if (ans.second == 1) {
    ans.first--;
    ans.second = 5;
  }
  if (ans < m[n]) {
    printf("-1\n");
    return 0;
  }
  printf("%d\n", ans.first);
  a[n] = ans.first;
  cnt[a[n]]++;
  for (int i = n - 1; i; i--) {
    a[i] = min(a[i + 1], M[i].first);
    if (cnt[a[i]] == 5) a[i]--;
    cnt[a[i]]++;
  }
  for (int i = 1; i <= n; i++) printf("%d ", a[i]);
  printf("\n");
  return 0;
}
