#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const long long MAX = 1e6;
const long long MOD = 1e9 + 7;
const long long base = 257;
const long double eps = 1e-7;
long long a[MAX], n;
string s;
vector<long long> v;
long long ans[MAX], l[MAX][6], r[MAX][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 (long long i = 2; i <= n; i++) {
    for (long long 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 (long long j = 2; j <= 5; j++) {
      if (l[i - 1][j] != -1) {
        if (l[i][1] == -1) {
          l[i][1] = INF;
        }
        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] > 0) {
      for (long long 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 (long long 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) {
    cout << "-1";
    return;
  }
  long long Ans = 0, j = 2;
  for (long long 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) {
    cout << "-1";
    return;
  }
  cout << Ans << "\n";
  long long old = n;
  while (n > 0) {
    for (long long i = 0; i < j; i++) {
      ans[n - i] = Ans;
    }
    n -= j;
    Ans--;
    for (long long i = 2; i <= 5; i++) {
      if (l[n][i] <= Ans && Ans <= r[n][i]) {
        j = i;
      }
    }
  }
  cout << ans[1] << " ";
  for (long long i = 2; i <= old; i++) {
    cout << ans[i] << " ";
  }
}
signed main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
  }
  solve();
  print();
}
