#include <bits/stdc++.h>
using namespace std;
long n;
vector<pair<long, long> > v;
long ar[300000];
long reach[300000][10];
long rspan, need1, need2;
long p, q;
long par[300000][10];
long ps, cur;
long tp, np, niters, m2, m1, qq;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  v.push_back(make_pair(0, 0));
  for (int i = 1; i <= n; i++) {
    cin >> ar[i];
    if (ar[i] > 0) v.push_back(make_pair(ar[i], i));
  }
  reach[0][5] = 1;
  for (int i = 1; i < v.size(); i++)
    if (v[i].first < v[i - 1].first) {
      cout << -1 << endl;
      return 0;
    }
  for (int i = 0; i + 1 < v.size(); i++) {
    rspan = v[i + 1].second - v[i].second;
    for (int op = 1; op <= 5; op++)
      for (int np = 1; np <= 5; np++) {
        if (reach[i][op] == 0) continue;
        if (v[i + 1].first == v[i].first && np <= op) continue;
        if (v[i + 1].first == v[i].first) {
          need1 = need2 = np - op;
        } else {
          need1 = (5 - op) + (v[i + 1].first - v[i].first - 1) * 5 + np;
          need2 = (v[i + 1].first - v[i].first - 1) * 2 + np;
          if (op == 1) need2++;
        }
        if (rspan >= need2 && rspan <= need1) {
          reach[i + 1][np] = 1;
          par[i + 1][np] = op;
        }
      }
  }
  if (v[v.size() - 1].second == n) reach[v.size() - 1][1] = 0;
  if (v[v.size() - 1].second == n - 1) reach[v.size() - 1][5] = 0;
  p = v.size() - 1;
  q = 2;
  while ((q <= 5 && reach[p][q] == 0)) ++q;
  if (q == 6)
    if (reach[p][1]) q = 1;
  if (q == 6) {
    cout << -1 << endl;
    return 0;
  }
  if (v[p].second == n - 1)
    ar[n] = ar[n - 1];
  else {
    ps = v[p].second;
    if (q == 1) {
      ++ps;
      ar[ps] = ar[ps - 1];
    }
    cur = ar[ps] + 1;
    ++ps;
    while (ps + 2 <= n) {
      if (ps + 2 == n) {
        ar[ps] = ar[ps + 1] = ar[ps + 2] = cur;
        ++cur;
        ps += 3;
      } else {
        ar[ps] = ar[ps + 1] = cur;
        cur++;
        ps += 2;
      }
    }
    if (ps < n) {
      ar[ps] = cur;
      ar[ps + 1] = cur;
      cur++;
      ps += 2;
    } else if (ps == n) {
      ar[ps] = cur - 1;
      ++ps;
    }
  }
  for (int i = v.size() - 1; i; --i) {
    if (v[i - 1].first == v[i].first) {
      for (int j = v[i - 1].second + 1; j < v[i].second; j++) {
        ar[j] = ar[v[i - 1].second];
      }
      q = par[i][q];
      continue;
    } else {
      for (int j = q; j >= 1; j--) ar[v[i].second - q + j] = ar[v[i].second];
      tp = v[i].second - q;
      np = par[i][q];
      niters = v[i].first - v[i - 1].first - 1;
      for (; niters; --niters) {
        m2 = (niters - 1) * 5 + (5 - np);
        qq = 2;
        while (tp - qq > (v[i - 1].second + m2)) ++qq;
        for (int j = tp - qq + 1; j <= tp; j++) ar[j] = v[i - 1].first + niters;
        tp = tp - qq;
      }
      for (int j = v[i - 1].second; j <= tp; j++) ar[j] = v[i - 1].first;
      q = np;
    }
  }
  cout << ar[n] << endl;
  for (int i = 1; i <= n; i++)
    if (ar[i] == 0) ar[i] = 1;
  for (int i = 1; i <= n; i++) {
    if (i - 1) cout << " ";
    cout << ar[i];
  }
  cout << endl;
  cin.get();
  cin.get();
  return 0;
}
