#include <bits/stdc++.h>
using namespace std;
int n, a[200005], b[200005], be[200005], en[200005], pr[200005], g[200005][25];
bool f[200005][25];
void solve(int p, int q) {
  if (!p) return;
  int i, j, u = q / 5, v = q % 5, e = g[p][q], y = e % 5, cnt = p - pr[p] - 1,
            up, dn;
  for (i = en[p] + 1; i <= en[p] + v; i++) a[i] = p;
  for (i = be[p] - 1; i >= be[p] - u; i--) a[i] = p;
  up = be[p] - u - 1, dn = en[pr[p]] + y + 1;
  for (i = dn; i <= up; i += 5) {
    if (up - i - 4 < 2 * (cnt - 1)) {
      j = up - i + 1 - 2 * (cnt - 1);
      for (; j; j--, i++) a[i] = p - cnt;
      cnt--;
      break;
    } else
      a[i] = a[i + 1] = a[i + 2] = a[i + 3] = a[i + 4] = p - cnt, cnt--;
  }
  for (; i <= up; i += 2) a[i] = a[i + 1] = p - cnt, cnt--;
  solve(pr[p], g[p][q]);
}
int main() {
  int i, j, p, u, v, x, y;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]), b[i] = a[i];
  for (i = 1; i <= n; i++)
    if (a[i]) en[a[i]] = i;
  for (i = n; i >= 1; i--)
    if (a[i]) be[a[i]] = i;
  if (be[1]) be[1] = 1;
  for (i = 1; i <= n; i++)
    if (be[i]) {
      for (j = be[i]; j <= en[i]; j++) a[j] = i;
      if (en[i] - be[i] + 1 > 5) {
        printf("-1");
        return 0;
      }
    }
  p = 0;
  for (i = 1; i <= n; i++)
    if (be[i]) pr[i] = p, p = i;
  f[0][0] = 1;
  for (i = 1; i <= n; i++)
    if (be[i]) {
      p = pr[i];
      for (j = 0; j < 25; j++) {
        u = j / 5, v = j % 5;
        if (!f[p][j]) continue;
        for (x = 0; x < 5; x++) {
          if (be[i] - x - (en[p] + v) - 1 < 2 * (i - p - 1)) break;
          if (be[i] - x - (en[p] + v) - 1 <= 5 * (i - p - 1)) {
            for (y = 0; y < 5; y++)
              if (x + y + en[i] - be[i] + 1 <= 5 &&
                  x + y + en[i] - be[i] + 1 >= 2)
                f[i][x * 5 + y] = 1, g[i][x * 5 + y] = j;
          }
        }
      }
    }
  for (i = n; i >= 1; i--)
    if (be[i]) break;
  p = i, x = (1 << 30), y = 0;
  for (i = 0; i < 5; i++)
    for (j = 0; j < 5; j++)
      if (i + j + en[p] - be[p] + 1 <= 5 &&
          ((i + j + en[p] - be[p] + 1 >= 2) || !p) && f[p][i * 5 + j] &&
          en[p] + j != n - 1)
        if (j < x) x = j, y = i * 5 + j;
  if (x == (1 << 30)) {
    printf("-1");
    return 0;
  }
  int xyk = p + (n - en[p] - x) / 2;
  x = p;
  for (i = en[p] + j % 5 + 1; i <= n; i += 2) {
    a[i] = a[i + 1] = ++x;
    if (i + 3 > n) a[(++i) + 1] = x;
  }
  solve(p, y);
  memset(be, 0, sizeof(be));
  memset(en, 0, sizeof(en));
  for (i = 1; i <= n; i++) en[a[i]] = i;
  for (i = n; i >= 1; i--) be[a[i]] = i;
  for (i = 1; i <= n; i++) {
    if (be[i] && (en[i] - be[i] + 1 > 5 || en[i] - be[i] + 1 < 2)) break;
    if (b[i] && a[i] != b[i]) break;
  }
  if (i <= n) {
    printf("-1");
    return 0;
  }
  cout << xyk << endl;
  for (i = 1; i <= n; i++) printf("%d ", a[i]);
  return 0;
}
