#include <bits/stdc++.h>
using namespace std;
int n, a[300000], ans[300000], l[300000][6], r[300000][6];
void solve() {
  memset(l, -1, sizeof(l));
  memset(r, -1, sizeof(r));
  if (a[1] > 1) {
    ans[0] = -1;
    return;
  }
  l[1][1] = r[1][1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 2; j <= 5; j++)
      if (l[i - 1][j - 1] != -1)
        l[i][j] = l[i - 1][j - 1], r[i][j] = r[i - 1][j - 1];
    for (int j = 2; j <= 5; j++)
      if (l[i - 1][j] != -1) {
        if (l[i][1] == -1) l[i][1] = ~0U >> 1;
        l[i][1] = min(l[i][1], l[i - 1][j] + 1);
        r[i][1] = max(r[i][1], r[i - 1][j] + 1);
      }
    bool flag = 0;
    if (a[i]) {
      for (int j = 1; j <= 5; j++)
        if (l[i][j] != -1) {
          if (l[i][j] <= a[i] && a[i] <= r[i][j])
            l[i][j] = r[i][j] = a[i];
          else
            l[i][j] = r[i][j] = -1;
        } else
          r[i][j] = -1;
    }
    for (int j = 1; j <= 5; j++)
      if (l[i][j] <= r[i][j] && l[i][j] != -1) flag = 1;
    if (!flag) {
      ans[0] = -1;
      return;
    }
  }
}
void print() {
  if (ans[0] == -1) {
    puts("-1");
    return;
  }
  int Ans = 0, j = 2;
  for (int i = 2; i <= 5; i++)
    if (l[n][i] <= r[n][i] && l[n][i] != -1) {
      if (r[n][i] > Ans) j = i, Ans = r[n][i];
    }
  if (Ans <= 0) {
    puts("-1");
    return;
  }
  printf("%d\n", Ans);
  int old = n;
  while (n > 0) {
    for (int i = 0; i < j; i++) ans[n - i] = Ans;
    n -= j;
    Ans--;
    for (int i = 2; i <= 5; i++)
      if (l[n][i] <= Ans && Ans <= r[n][i]) j = i;
  }
  printf("%d", ans[1]);
  for (int i = 2; i <= old; i++) printf(" %d", ans[i]);
  puts("");
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  solve();
  print();
}
