#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const int MOD = 1e9 + 7;
const int N = 2e5 + 10;
int n, a[N] = {0}, T[N][6] = {0}, ans[N];
void solve() {
  T[0][5] = -1;
  for (auto i = 1; i <= n; i++)
    if (a[i]) {
      int j = i + 1;
      while (j <= n && !a[j]) j++;
      if (j <= n) {
        if (a[j] < a[i]) {
          printf("-1");
          return;
        };
        if (a[j] == a[i])
          for (auto k = i + 1; k <= j; k++) a[k] = a[i];
      }
      i = j - 1;
    }
  for (auto i = 0; i < n; i++) {
    int j = i + 1;
    while (j <= n && !a[j]) j++;
    if (j > n) break;
    if (j == i + 1 && a[j] == a[i]) {
      for (auto nlen = 5; nlen >= 2; nlen--)
        if (T[i][nlen - 1]) T[j][nlen] = nlen - 1;
    } else
      for (auto clen = 1; clen <= 5; clen++)
        if (T[i][clen]) {
          for (auto nlen = 1; nlen <= 5; nlen++) {
            int nR = j - nlen, nL = i + 1 + (clen < 2);
            if (nR < nL - 1) continue;
            int rR = (nR - nL + 1) / 2,
                rL = max(nR - i - (5 - clen) + 4, 0) / 5;
            if (a[j] - a[i] - 1 < rL || a[j] - a[i] - 1 > rR) continue;
            T[j][nlen] = clen;
          }
        }
    if (count(T[j] + 1, T[j] + 6, 0) == 5) {
      printf("-1");
      return;
    };
    i = j - 1;
  }
  int pos = n;
  while (pos && a[pos] == 0) pos--;
  int st = 5 - (pos == n - 1);
  while (st && !T[pos][st]) st--;
  if (st <= (pos == n)) {
    printf("-1");
    return;
  };
  for (auto i = pos + 1; i <= n; i++) {
    if (i == pos + 1)
      ans[i] = (st < 2 || i == n) ? a[pos] : a[pos] + 1;
    else
      ans[i] = ans[i - 1] + (ans[i - 1] == ans[i - 2] && i < n);
  }
  while (pos) {
    int nex = pos - 1;
    while (nex && !a[nex]) nex--;
    if (nex == pos - 1 && a[nex] == a[pos]) {
      ans[pos] = a[pos];
      pos--;
      st--;
      continue;
    }
    for (auto i = pos; i >= pos - st + 1; i--) ans[i] = a[pos];
    int tmp = st;
    st = T[pos][st];
    pos -= tmp;
    if (ans[pos + 1] == a[nex] + 1)
      for (auto i = nex + 1; i <= pos; i++) ans[i] = a[nex];
    else {
      if (st < 2) ans[nex + 1] = a[nex];
      int each = (pos - nex - (st < 2)) / (ans[pos + 1] - a[nex] - 1);
      if (each >= 5)
        for (auto i = pos; i >= nex + 1; i--)
          ans[i] = ans[pos + 1] - (pos - i) / 5 - 1;
      else {
        int j = pos, add = (pos - nex - (st < 2)) % (ans[pos + 1] - a[nex] - 1);
        for (auto i = 1; i <= ans[pos + 1] - a[nex] - 1; i++)
          for (auto k = 1; k <= each + (i <= add); k++)
            ans[j--] = ans[pos + 1] - i;
      }
    }
    pos = nex;
  }
  printf("%d\n", ans[n]);
  for (auto i = 1; i <= n; i++) printf("%d ", ans[i]);
}
int main() {
  scanf("%d", &n);
  for (auto i = 1; i <= n; i++) scanf("%d", a + i);
  solve();
}
