#include <bits/stdc++.h>
using namespace std;
const int ONE = 1000005;
const int MOD = 1e9 + 7;
int n;
int a[ONE];
int vis[ONE], ans[ONE];
struct power {
  int val, times;
  friend bool operator<(power a, power b) {
    if (a.val != b.val) return a.val < b.val;
    return a.times < b.times;
  }
} low[ONE], up[ONE];
int get() {
  int res;
  char c;
  while ((c = getchar()) < 48 || c > 57)
    ;
  res = c - 48;
  while ((c = getchar()) >= 48 && c <= 57) res = res * 10 + c - 48;
  return res;
}
void Deal_first() {
  low[1] = up[1] = (power){1, 1};
  for (int i = 2; i <= n; i++) {
    low[i] = low[i - 1], up[i] = up[i - 1];
    if (++low[i].times > 5) low[i] = (power){low[i].val + 1, 1};
    if (++up[i].times > 2) up[i] = (power){up[i].val + 1, 1};
    if (a[i] != 0) {
      if (low[i].val > a[i] || up[i].val < a[i]) {
        printf("-1");
        exit(0);
      }
      low[i] = max(low[i], (power){a[i], 1});
      up[i] = min(up[i], (power){a[i], 5});
    }
    if (low[i].val > up[i].val) {
      printf("-1");
      exit(0);
    }
  }
}
int main() {
  n = get();
  for (int i = 1; i <= n; i++) a[i] = get();
  if (a[1] > 1) {
    printf("-1");
    exit(0);
  }
  Deal_first();
  int val = up[n].val - (up[n].times == 1);
  if (low[n].val > val) {
    printf("-1");
    exit(0);
  }
  for (int i = n; i >= 1; i--) {
    val = min(val, up[i].val);
    val -= vis[val] == 5;
    ans[i] = val, vis[val]++;
  }
  if (ans[1] <= 0) {
    printf("-1");
    exit(0);
  }
  printf("%d\n", ans[n]);
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
}
