#include <bits/stdc++.h>
using namespace std;
int n, a[200005], f[200005][10], len, val[200005];
pair<int, int> b[200005];
int sum[200005], sl[200005], l[200005], r[200005];
void home() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
}
int get(int sz) { return sz / 2; }
bool check(int sz, int p) {
  if (p == 0 && sz) return 0;
  if (sz == 0 && p) return 0;
  if (sz == 0 && p == 0) return 1;
  if (sz <= 1) return 0;
  int x = sz / 5;
  if (sz % 5) x++;
  return (p >= x && p <= sz / 2);
}
int cal(int i, int k) {
  if (i == 1) {
    int tmp = b[i].first - b[i - 1].second - 1 - k;
    return (check(tmp, val[i] - 1));
  }
  if (f[i][k] != -1) return f[i][k];
  int ans = 0;
  for (int kk = (0); kk <= (5); ++kk)
    for (int hh = (0); hh <= (5); ++hh)
      if (hh + kk + b[i - 1].second - b[i - 1].first + 1 >= 2 &&
          hh + kk + b[i - 1].second - b[i - 1].first + 1 <= 5 &&
          kk <= b[i - 1].first - b[i - 2].second - 1 &&
          hh + k <= b[i].first - b[i - 1].second - 1 &&
          check(b[i].first - b[i - 1].second - 1 - hh - k,
                val[i] - val[i - 1] - 1))
        ans = max(ans, cal(i - 1, kk));
  return f[i][k] = ans;
}
void up(int l, int r, int x, int y) {
  if (x > y) return;
  int dem = 0;
  for (int j = (l); j <= (r); ++j) {
    if (x == y) {
      a[j] = x;
      continue;
    };
    if (dem >= 2)
      if (dem == 5 || check(r - j + 1, y - x)) x++, dem = 0;
    a[j] = x;
    dem++;
  }
}
void tv(int i, int k) {
  for (int j = (b[i].first - k); j <= (b[i].first - 1); ++j) a[j] = val[i];
  if (i == 1) {
    up(1, b[i].first - b[i - 1].second - 1 - k, 1, val[i] - 1);
    return;
  }
  for (int kk = (0); kk <= (5); ++kk)
    for (int hh = (0); hh <= (5); ++hh)
      if (hh + kk + b[i - 1].second - b[i - 1].first + 1 >= 2 &&
          hh + kk + b[i - 1].second - b[i - 1].first + 1 <= 5 &&
          kk <= b[i - 1].first - b[i - 2].second - 1 &&
          hh + k <= b[i].first - b[i - 1].second - 1 &&
          check(b[i].first - b[i - 1].second - 1 - hh - k,
                val[i] - val[i - 1] - 1) &&
          cal(i - 1, kk) == 1) {
        for (int j = (b[i - 1].second + 1); j <= (b[i - 1].second + hh); ++j)
          a[j] = val[i - 1];
        up(b[i - 1].second + hh + 1, b[i].first - k - 1, val[i - 1] + 1,
           val[i] - 1);
        tv(i - 1, kk);
        return;
      }
}
int main() {
  home();
  cin >> n;
  for (int i = (1); i <= (n); ++i) {
    cin >> a[i];
    if (a[i] > n / 2) {
      cout << -1;
      return 0;
    }
    sl[i] = sl[i - 1] + (a[i] > 0);
    sum[i] = sum[i - 1] + a[i];
  }
  for (int i = (1); i <= (n); ++i)
    if (a[i] && !l[a[i]]) l[a[i]] = i;
  for (int i = (n); i >= (1); --i)
    if (a[i] && !r[a[i]]) r[a[i]] = i;
  for (int i = (1); i <= (n); ++i) {
    if (r[i] - l[i] + 1 > 5) {
      cout << -1;
      return 0;
    }
    if (l[i] && sum[r[i]] - sum[l[i] - 1] != (sl[r[i]] - sl[l[i] - 1]) * i) {
      cout << -1;
      return 0;
    }
    if (l[i]) {
      b[++len] = pair<int, int>(l[i], r[i]);
      val[len] = i;
    }
  }
  if (len == 0) {
    cout << get(n) << "\n";
    up(1, n, 1, get(n));
    for (int i = (1); i <= (n); ++i) cout << a[i] << " ";
  } else {
    for (int i = (1); i <= (len); ++i)
      for (int j = (b[i].first); j <= (b[i].second); ++j) a[j] = val[i];
    memset(f, -1, sizeof(f));
    int ans = 0;
    pair<int, int> nh;
    for (int k = (0); k <= (5); ++k)
      for (int h = (0); h <= (5); ++h)
        if (h + k + b[len].second - b[len].first + 1 >= 2 &&
            h + k + b[len].second - b[len].first + 1 <= 5 &&
            k <= b[len].first - b[len - 1].second - 1 &&
            h <= n - b[len].second) {
          int tmp = cal(len, k);
          if (tmp == 1 &&
              check(n - b[len].second - h, get(n - b[len].second - h)) &&
              ans < val[len] + get(n - b[len].second - h)) {
            ans = val[len] + get(n - b[len].second - h);
            nh = pair<int, int>(k, h);
          }
        }
    if (ans == 0)
      cout << -1;
    else {
      cout << ans << "\n";
      for (int j = (b[len].second + 1); j <= (b[len].second + nh.second); ++j)
        a[j] = val[len];
      if (n - b[len].second - nh.second > 0)
        up(b[len].second + nh.second + 1, n, val[len] + 1,
           val[len] + get(n - b[len].second - nh.second));
      tv(len, nh.first);
      int ii;
      for (int i = (1); i <= (n); ++i)
        if (a[i] > 0) {
          ii = i;
          break;
        }
      if (ii - 1 > 0) up(1, ii - 1, 1, a[ii] - 1);
      for (int i = (1); i <= (n); ++i) cout << a[i] << " ";
    }
  }
}
