#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int n, a[maxn];
int mx[maxn], mn[maxn];
vector<int> pos[maxn];
int l[maxn], r[maxn], Mx = 0;
int go(int i, int cur_l, int cur_r) {
  cur_r = min(mn[i], cur_r);
  int next_r = min(cur_r, mn[i]) + 5;
  int next_l = max(cur_l + 2, mx[i] + 1);
  if (next_l > next_r || cur_l > cur_r) return 0;
  int endPos = -1;
  if (cur_l < n) endPos = go(i + 1, next_l, next_r) - 1;
  if (endPos != -1) {
    for (int j = max(cur_l, endPos - 4); j <= endPos; j++) a[j] = i;
    return max(cur_l, endPos - 4);
  }
  if (cur_l >= n && i > Mx) return n + 1;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  fill(mx, mx + maxn, -1e9);
  fill(mn, mn + maxn, 1e9);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    mx[a[i]] = max(mx[a[i]], i);
    mn[a[i]] = min(mn[a[i]], i);
    Mx = max(Mx, a[i]);
  }
  if (go(1, 1, 1)) {
    cout << a[n] << "\n";
    for (int i = 1; i <= n; i++) cout << a[i] << ' ';
    return 0;
  }
  cout << -1;
}
