#include <bits/stdc++.h>
using namespace std;
long long int pow1(long long int a, long long int b,
                   long long int m = 1000000007) {
  if (b == 0)
    return 1ll;
  else if (b == 1)
    return a;
  else {
    long long int x = pow1(a, b / 2, m);
    x *= x;
    x %= m;
    if (b % 2) {
      x *= a;
      x %= m;
    }
    return x;
  }
}
template <class avgType>
avgType avg(avgType a, avgType b) {
  return (a + b) / 2;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
int randInt() { return rng() % INT_MAX; }
long long int randLL() { return rng64() % LLONG_MAX; }
vector<int> hashmods = {1000000007, 1000000009, 1000000021,
                        1000000033, 1000000087, 1000000093};
int n, a[210000], dp[210000][6], pres[210000], num[210000];
vector<int> v, v1;
map<pair<int, int>, int> done;
int solve(int x, int y, int val, int fin) {
  if (done.count(make_pair(x, y))) return done[make_pair(x, y)];
  done[make_pair(x, y)] = 0;
  int diff = (y - x + 1);
  int mid = (fin - val);
  if (mid > 0 and (2 * mid > diff or 5 * mid < diff)) {
    return 0;
  }
  int start_curr = v[lower_bound(v.begin(), v.end(), max(x, y)) - v.begin()];
  int end_curr = v1[lower_bound(v1.begin(), v1.end(), start_curr) - v1.begin()];
  int start_next = v[lower_bound(v.begin(), v.end(), end_curr + 1) - v.begin()];
  int curr = num[a[start_curr]] + (start_curr - y - 1);
  if (mid == 0) curr += diff;
  if (a[end_curr] == a[start_curr] and end_curr == n - 1) curr++;
  if (curr > 5) return 0;
  if (a[end_curr] != a[start_curr] and curr < 2) return 0;
  int cnt_last = (a[end_curr] != a[start_curr] ? num[a[end_curr]] : curr);
  if (start_next == n + 1) {
    if (cnt_last < 2 and end_curr == n) return 0;
    if (mid == 0) {
      for (int j = x; j <= y; j++) a[j] = val;
      for (int j = y + 1; j < start_curr; j++) a[j] = a[start_curr];
    } else {
      int avg = diff / mid;
      int lef = diff % mid;
      int curr_v = val, curr_n = 0;
      for (int j = x; j <= y; j++) {
        curr_n++;
        a[j] = curr_v;
        if (lef == 0 and curr_n == avg) {
          curr_n = 0;
          curr_v++;
        } else if (curr_n == avg + 1) {
          lef--;
          curr_n = 0;
          curr_v++;
        }
      }
      for (int j = y + 1; j < start_curr; j++) a[j] = a[start_curr];
    }
    done[make_pair(x, y)] = 1;
  } else {
    int minim = (cnt_last >= 2 ? end_curr + 1 : end_curr + 2);
    int maxim = end_curr + (6 - cnt_last);
    int f = 1;
    for (int i = minim; i <= maxim and f; i++) {
      for (int k = max(i, start_next - 4); k <= start_next; k++) {
        done[make_pair(x, y)] = solve(i, k - 1, a[end_curr] + 1, a[start_next]);
        if (done[make_pair(x, y)]) {
          for (int j = end_curr + 1; j < i; j++) a[j] = a[end_curr];
          f = 0;
          break;
        }
      }
    }
    if (done[make_pair(x, y)]) {
      if (mid == 0) {
        for (int j = x; j <= y; j++) a[j] = val;
        for (int j = y + 1; j < start_curr; j++) a[j] = a[start_curr];
      } else {
        int avg = diff / mid;
        int lef = diff % mid;
        int curr_v = val, curr_n = 0;
        for (int j = x; j <= y; j++) {
          curr_n++;
          a[j] = curr_v;
          if (lef == 0 and curr_n == avg) {
            curr_n = 0;
            curr_v++;
          } else if (curr_n == avg + 1) {
            lef--;
            curr_n = 0;
            curr_v++;
          }
        }
        for (int j = y + 1; j < start_curr; j++) a[j] = a[start_curr];
      }
    }
  }
  return done[make_pair(x, y)];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  memset(dp, -1, sizeof(dp));
  cin >> n;
  int prev = -1;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (i <= 2) {
      if (a[i] > 1) {
        cout << -1 << "\n";
        return 0;
      }
      a[i] = 1;
    }
    if (a[i] > 0) {
      if (prev != -1 and a[prev] != a[i] and pres[a[i]]) {
        cout << -1 << "\n";
        return 0;
      } else if (prev != -1 and a[prev] == a[i]) {
        if (i - prev > 4) {
          cout << -1 << "\n";
          return 0;
        }
        int curr = i - 1;
        while (a[curr] == 0) {
          a[curr] = a[i];
          curr--;
        }
        continue;
      } else {
        pres[a[i]] = 1;
        prev = i;
      }
    }
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    num[a[i]]++;
    if (cnt == 0 and a[i] > 0) {
      v.push_back(i);
      cnt++;
    } else if (a[i] > 0) {
      cnt++;
    } else if (cnt > 0) {
      v1.push_back(i - 1);
      cnt = 0;
    }
  }
  if (cnt) {
    v1.push_back(n);
  }
  v.push_back(n + 1);
  int ans = solve(1, 0, 1, 1);
  if (ans == 0) {
    cout << -1 << "\n";
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    num[i] = 0;
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] == 0) {
      if (i == n)
        a[i] = a[i - 1];
      else if (num[a[i - 1]] >= 2) {
        a[i] = a[i - 1] + 1;
      } else {
        a[i] = a[i - 1];
      }
    }
    num[a[i]]++;
    if (i > 1 and a[i] != a[i - 1] and ((a[i] - a[i - 1] != 1))) {
      cout << -1 << "\n";
      return 0;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (num[i] > 0 and (num[i] < 2 or num[i] > 5)) {
      cout << -1 << "\n";
      return 0;
    }
  }
  cout << a[n] << "\n";
  for (int i = 1; i <= n; i++) {
    cout << a[i] << " ";
  }
  cout << "\n";
  return 0;
}
