#include <bits/stdc++.h>
using namespace std;
struct node {
  int day, id;
};
vector<node> p;
int n, arr[200010];
bool f[200010][6];
bool check(node a, int x, node b, int y) {
  if (a.id == b.id)
    return b.day - a.day == y - x;
  else {
    int k = b.id - a.id, dif = b.day - a.day;
    int l, r;
    if (x == 1)
      l = 1 + (k - 1) * 2 + y, r = 4 + (k - 1) * 5 + y;
    else
      l = (k - 1) * 2 + y, r = (5 - x) + (k - 1) * 5 + y;
    return (l <= dif && dif <= r);
  }
}
void printans() {
  for (int i = 1; i <= n; i++) printf("%d%c", arr[i], i == n ? '\n' : ' ');
}
void getans(int book, int day, int read, int i) {
  int t;
  for (t = 0; t < read; t++) arr[day - t] = book;
  while (i >= 0 && p[i].day >= day - t + 1) i--;
  if (i < 0) return;
  t = day - read;
  node a = (node){t, book - 1};
  for (int x = 1; x <= 5; x++)
    for (int y = 2; y <= 5; y++)
      if (f[p[i].day][x] && check(p[i], x, a, y)) {
        getans(a.id, a.day, y, i);
        return;
      }
}
void solv() {
  if (arr[1] > 1) {
    printf("-1\n");
    return;
  }
  arr[1] = 1;
  for (int i = 1; i <= n; i++)
    if (arr[i]) p.push_back((node){i, arr[i]});
  f[1][1] = true;
  for (int i = 0; i < ((int)p.size() - 1); i++) {
    node a = p[i], b = p[i + 1];
    for (int j = 1; j <= 5; j++)
      if (f[a.day][j])
        for (int k = 1; k <= 5; k++)
          if (check(a, j, b, k)) f[b.day][k] = true;
  }
  for (int ans = 100000; ans >= 0; ans--) {
    node x = p[p.size() - 1];
    for (int i = 2; i <= 5; i++) {
      for (int j = 1; j <= 5; j++)
        if (f[x.day][j] && check(x, j, (node){n, ans}, i)) {
          getans(ans, n, i, p.size() - 1);
          printf("%d\n", ans);
          printans();
          return;
        }
    }
  }
  printf("-1\n");
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &arr[i]);
  solv();
  return 0;
}
