#include <bits/stdc++.h>
using namespace std;
int N;
int in[200010], lo[200010], hi[200010];
bool dp[200010][5];
int cur_put[200010][5], prev_put[200010][5];
void quit() {
  puts("-1");
  exit(0);
}
vector<pair<int, pair<int, int> > > grp;
bool valid(int lhi, int rlo) { return lhi < rlo; }
bool can_put(int how, int fr, int to) {
  if (fr > to) return how == 0;
  int span = to - fr + 1;
  return 2 * how <= span && span <= 5 * how;
}
int out[200010];
void paint(int lo, int hi, int to) {
  for (int i = lo; i <= hi; ++i) out[i] = to;
}
void paint_interval(int beg, int how, int fr, int to) {
  if (how <= 0) return;
  vector<int> cnt(how, 0);
  int len = to - fr + 1;
  for (int i = 0; len > 0; i = (i + 1 < how) ? i + 1 : 0) ++cnt[i], --len;
  for (int i = 0; i < ((int)(cnt).size()); ++i)
    paint(fr, fr + cnt[i] - 1, beg + i), fr += cnt[i];
}
void prepare(int sft) {
  int rg = ((int)(grp).size()) - 1;
  while (rg > 0) {
    int rlo = grp[rg].second.first - cur_put[rg][sft],
        rhi = grp[rg].second.second + sft;
    paint(rlo, rhi, grp[rg].first);
    sft = prev_put[rg][sft];
    int lhi = grp[rg - 1].second.second + sft;
    paint_interval(grp[rg - 1].first + 1, grp[rg].first - grp[rg - 1].first - 1,
                   lhi + 1, rlo - 1);
    --rg;
  }
}
int main() {
  for (int i = 0; i < 200010; ++i) {
    lo[i] = 1000000000;
    hi[i] = -1;
  }
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &in[i]);
    if (in[i]) {
      (hi[in[i]]) = max((hi[in[i]]), (i));
      (lo[in[i]]) = min((lo[in[i]]), (i));
    }
  }
  for (int i = 0; i < 200010; ++i)
    if (lo[i] <= hi[i]) grp.push_back(make_pair(i, make_pair(lo[i], hi[i])));
  for (int i = 1; i < ((int)(grp).size()); ++i) {
    if (grp[i - 1].first > grp[i].first) quit();
    if (grp[i - 1].second.second > grp[i].second.first) quit();
  }
  dp[0][0] = true;
  grp.insert(grp.begin(), make_pair(0, make_pair(0, 0)));
  for (int i = 1; i < ((int)(grp).size()); ++i) {
    for (int give = 0; give < 5; ++give)
      for (int lo = 0; lo < 5; ++lo) {
        int fr = grp[i].second.first - lo, to = grp[i].second.second + give;
        if (to - fr + 1 > 5) continue;
        if (to - fr + 1 < 2) continue;
        for (int pgive = 0; pgive < 5; ++pgive) {
          if (!dp[i - 1][pgive]) continue;
          int phi = grp[i - 1].second.second + pgive;
          if (!valid(phi, fr)) continue;
          if (can_put(grp[i].first - grp[i - 1].first - 1, phi + 1, fr - 1)) {
            dp[i][give] = true;
            cur_put[i][give] = lo;
            prev_put[i][give] = pgive;
            break;
          }
        }
      }
  }
  int fg = -1;
  for (int sft = 0; sft < 5; ++sft) {
    if (!dp[((int)(grp).size()) - 1][sft]) continue;
    int Left = N - (grp.back().second.second + sft);
    if (Left == 1) continue;
    if (Left < 0) continue;
    fg = sft;
    break;
  }
  if (fg == -1) quit();
  prepare(fg);
  if (out[N] == 0) {
    int Last = N;
    while (Last - 1 >= 1 && out[Last - 1] == 0) --Last;
    int cur = (Last == 1) ? 1 : out[Last - 1] + 1;
    while (Last + 1 <= N) {
      out[Last] = out[Last + 1] = cur++;
      Last += 2;
    }
    if (out[N] == 0) out[N] = out[N - 1];
  }
  printf("%d\n", out[N]);
  for (int i = 1; i <= N; ++i) printf("%d%c", out[i], (i == N ? '\n' : ' '));
  return 0;
}
