#include <bits/stdc++.h>
using namespace std;
int const lim = 2e5 + 3;
int const MLOG = 20;
int mod = 1e9 + 7;
int a[lim + 3];
bool dp[lim + 3][5];
vector<pair<int, int> > vec;
bool vis[lim + 3];
int from[lim + 3][5], extra[lim + 3][5];
int n;
int check(int ind, int mn, int mx, int ks) {
  int num = a[vec[ind].first] - a[vec[ind - 1].first] - 1;
  int con = -1;
  for (int i = 0; i <= 4; i++) {
    for (int j = mn; j <= mx; j++) {
      int l = vec[ind - 1].second + i + 1, r = vec[ind].first - j - 1;
      if (l > n || r < 0) continue;
      if (!num && r - l == -1 && dp[ind - 1][i]) {
        extra[ind][ks] = j;
        return i;
      }
      if (r >= l && r - l + 1 >= 2 * num && r - l + 1 <= 5 * num &&
          dp[ind - 1][i]) {
        extra[ind][ks] = j;
        return i;
      }
    }
  }
  return -1;
}
void print(int i, int j) {
  if (!i) return;
  int ind = vec[i].second;
  for (int k = ind + 1; k <= ind + j; k++) a[k] = a[ind];
  int num = a[ind] - a[vec[i - 1].first] - 1;
  int f = from[i][j];
  int ex = extra[i][j];
  for (int k = vec[i].first - ex; k < vec[i].first; k++) a[k] = a[ind];
  int l = vec[i - 1].second + f + 1, r = vec[i].first - ex - 1;
  if (l > r) return print(i - 1, f);
  int dif = (r - l + 1) / num;
  for (int k = a[ind] - num; k < a[ind]; k++) {
    int cnt = 0;
    int rem = a[ind] - k - 1;
    while (l <= r && cnt < 5 && (r - l) >= 2 * rem) a[l++] = k, cnt++;
  }
  print(i - 1, f);
}
int main() {
  cin >> n;
  int last = -1, ind = -1;
  vec.push_back(make_pair(0, 0));
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == 0) continue;
    if (a[i] == last) {
      if (i - ind + 1 > 5) return puts("-1"), 0;
      for (int j = ind; j < i; j++) a[j] = last;
      vec.back().second = i;
    } else if (vis[a[i]])
      return puts("-1"), 0;
    else
      last = a[i], ind = i, vec.push_back(make_pair(i, i));
    vis[a[i]] = true;
  }
  ind = vec.back().second;
  if (ind + 1 == n && a[ind + 1] == 0)
    a[ind + 1] = a[ind], vec[vec.size() - 1].second++;
  if (vec.back().second - vec.back().first + 1 > 5) return puts("-1"), 0;
  dp[0][0] = true;
  for (int i = 1; i < vec.size(); i++) {
    int len = vec[i].second - vec[i].first + 1;
    if (len > 5 || a[vec[i].first] <= a[vec[i - 1].first]) return puts("-1"), 0;
    for (int j = 0; j + len <= 5; j++) {
      if (vec[i].second + j > n) continue;
      int ind = check(i, max(0, 2 - (len + j)), 5 - (j + len), j);
      if (ind != -1) dp[i][j] = true, from[i][j] = ind;
    }
  }
  int sz = vec.size();
  for (int i = 0; i <= 4; i++) {
    if (dp[sz - 1][i]) {
      int j = vec[sz - 1].second + i;
      int last = a[vec[sz - 1].first];
      j++;
      for (; j <= n; j += 2) {
        if (j + 1 <= n)
          a[j] = a[j + 1] = ++last;
        else
          a[j] = last;
      }
      cout << last << endl;
      print(sz - 1, i);
      for (int i = 1; i <= n; i++) printf("%d ", a[i]);
      return 0;
    }
  }
  return puts("-1"), 0;
}
