#include <bits/stdc++.h>
using namespace std;
const int MAX = 200000 + 10;
const int NUM = 10;
int n;
int a[MAX], f[MAX][NUM], comex[MAX][NUM], comey[MAX][NUM];
void fill(int l, int r, int be, int num) {
  if (!num) return;
  int c = (r - l + 1) / num;
  int res = (r - l + 1) % num;
  int i;
  for ((i) = (1); (i) <= (num); ++(i)) {
    int d = c + (res > 0);
    while (d--) a[l++] = be;
    res--;
    be++;
  }
}
int main() {
  int i, j, k;
  scanf("%d", &n);
  for ((i) = (1); (i) <= (n); ++(i)) scanf("%d", &a[i]);
  f[0][5] = 1;
  int last = 0;
  for ((i) = (1); (i) <= (n); ++(i))
    if (a[i]) {
      for (j = 1; j <= 5; ++j)
        if (f[last][j])
          for ((k) = (1); (k) <= (5); ++(k)) {
            if (a[i] != a[last]) {
              int must = 0;
              if (j == 1) must++;
              must += k - 1;
              if (must + (a[i] - a[last] - 1) * 2 > i - last - 1) continue;
              int could = 5 - j;
              could += k - 1;
              if (could + (a[i] - a[last] - 1) * 5 < i - last - 1) continue;
            } else if (k - j != i - last)
              continue;
            f[i][k] = 1;
            comex[i][k] = last;
            comey[i][k] = j;
          }
      last = i;
    }
  for (k = 5; k >= 1; --k)
    if (f[last][k]) {
      if (last + 1 == n && k == 5) continue;
      break;
    }
  if (k == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (k == 1 && last + 1 > n) {
    cout << -1 << endl;
    return 0;
  }
  i = last;
  if (k == 1) a[++i] = a[last];
  int num = a[last];
  for (++i; i + 1 <= n; i += 2) a[i + 1] = a[i] = ++num;
  if (i == n) a[i] = num;
  while (last) {
    int t = comex[last][k];
    if (a[t] == a[last]) {
      for ((i) = (t); (i) <= (last); ++(i)) a[i] = a[t];
    } else {
      for ((j) = (1); (j) != (k); ++(j)) a[last - j] = a[last];
      int l = t + 1, r = last - k;
      int u = comey[last][k];
      for (; r - l >= (a[last] - a[t] - 1) * 2 && u < 5; ++u, ++l) a[l] = a[t];
      fill(l, r, a[t] + 1, a[last] - a[t] - 1);
    }
    k = comey[last][k];
    last = t;
  }
  cout << a[n] << endl;
  for ((i) = (1); (i) <= (n); ++(i)) cout << a[i] << " ";
  cout << endl;
  return 0;
}
