#include <bits/stdc++.h>
using namespace std;
int i, j, k, n, m, u;
int s[200010], id[200010], be[200010], f[200010][6], h[200010][6], a[200010],
    b[200010], en[200010];
inline bool judge() {
  int A = u - j, B = k - s[i], C = be[i] - A - B, D = b[i] - b[i - 1] - 1;
  return 2 * D <= C && C <= 5 * D;
}
inline void tian(int x) {
  int i, j, k;
  for (i = m; i; i--) {
    int A = x - s[i];
    for (j = 1; j <= A; j++) a[id[i] - j] = b[i];
    A = f[i][x] - h[i][x];
    for (j = 1; j <= A; j++) a[en[i - 1] + j] = b[i - 1];
    A = b[i] - b[i - 1] - 1;
    if (!A) {
      x = h[i][x];
      continue;
    }
    int D = be[i] - (x - s[i]) - (f[i][x] - h[i][x]);
    int B = D / A, C = en[i - 1] + f[i][x] - h[i][x] + 1;
    for (j = 1; j <= A; j++)
      for (k = 1; k <= (j <= D % A) + B; k++) a[C++] = b[i - 1] + j;
    x = h[i][x];
  }
}
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  {
    for (i = 1; i <= n;) {
      for (; i <= n && !a[i]; i++)
        ;
      if (i > n) break;
      for (j = i + 1; j <= n && !a[j]; j++)
        ;
      if (a[i] == a[j])
        for (k = i + 1; k <= j - 1; k++) a[k] = a[i];
      i = j;
    }
    id[0] = -4, s[0] = 5;
    for (i = 1; i <= n;) {
      int A = i;
      for (; i <= n && !a[i]; i++)
        ;
      if (i > n) break;
      for (j = i + 1; j <= n && a[i] == a[j]; j++)
        ;
      id[++m] = i;
      s[m] = j - i;
      be[m] = i - A;
      b[m] = a[i];
      en[m] = j - 1;
      i = j;
    }
  }
  {
    f[0][5] = 1;
    for (i = 1; i <= m; i++)
      for (j = s[i - 1]; j <= 5; j++)
        if (f[i - 1][j])
          for (u = max(2, j); u <= 5; u++)
            for (k = s[i]; k <= 5; k++)
              if (judge()) f[i][k] = u, h[i][k] = j;
  }
  {
    for (i = 5; i; i--)
      if (f[m][i]) {
        if (i == 5 && en[m] + 1 == n) continue;
        if (i == 1 && en[m] == n) continue;
        int A = en[m] + 1, B = b[m];
        if (i == 1) a[A++] = B;
        for (j = A; j < n; j += 2) a[j] = a[j + 1] = ++B;
        for (; j <= n; j++) a[j] = a[j - 1];
        tian(i);
        printf("%d\n", B);
        for (j = 1; j <= n; j++) printf("%d ", a[j]);
        return 0;
      }
  }
  printf("-1\n");
  return 0;
}
