#include <bits/stdc++.h>
using namespace std;
struct block {
  int ini;
  int end;
  int val;
  block() {}
  block(int ini, int end, int val) : ini(ini), end(end), val(val) {}
};
struct seg {
  int ini;
  int end;
  int end_prev;
  seg() {}
  seg(int ini, int end, int end_prev)
      : ini(ini), end(end), end_prev(end_prev) {}
};
int a[((int)2e5 + 5)];
vector<int> g[((int)2e5 + 5)];
vector<block> v;
int dp[((int)2e5 + 5)][5];
seg p[((int)2e5 + 5)][5];
int n;
inline int can_fill(int space, int qt) {
  return 2 * qt <= space && space <= 5 * qt;
}
void solve(int pos) {
  if (pos >= (int)v.size() - 1) {
    return;
  }
  int ini = v[pos].ini;
  int end = v[pos].end;
  int qt = v[pos].val - v[pos - 1].val - 1;
  int space = v[pos].ini - v[pos - 1].end - 1;
  for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 5; j++) {
      for (int k = 0; k < 5; k++) {
        int len = end + j - (ini - i) + 1;
        if (2 <= len && len <= 5 && dp[pos - 1][k] &&
            can_fill(space - i - k, qt) && ini - i > v[pos - 1].end + k &&
            end + j < v[pos + 1].ini) {
          dp[pos][j] = 1;
          p[pos][j] = seg(ini - i, end + j, k);
        }
      }
    }
  }
  solve(pos + 1);
  return;
}
void fill(int x, int y, int ini, int end) {
  int pos = ini;
  for (int i = x; i <= y; i++) {
    for (int j = 2; j <= 5; j++) {
      int len = end - pos + 1 - j;
      int qt = y - i;
      if (can_fill(len, qt)) {
        for (int k = 0; k < j; k++) {
          a[pos + k] = i;
        }
        pos += j;
        break;
      }
    }
  }
  return;
}
void get_ans(int pos, int inc) {
  while (pos != 0) {
    int aux = p[pos][inc].ini - 1;
    for (int i = p[pos][inc].ini; i <= p[pos][inc].end; i++) {
      a[i] = v[pos].val;
    }
    inc = p[pos][inc].end_prev;
    pos--;
    fill(v[pos].val + 1, v[pos + 1].val - 1, p[pos][inc].end + 1, aux);
  }
  return;
}
int main(void) {
  int ok = 1;
  scanf(" %d", &n);
  for (int i = 1; i <= n; i++) {
    scanf(" %d", &a[i]);
    g[a[i]].push_back(i);
  }
  int last = 0;
  v.push_back(block(0, 0, 0));
  for (int i = 1; i < ((int)2e5 + 5); i++) {
    if (g[i].size() > 0 && g[i][0] < last) {
      ok = 0;
      break;
    } else if (g[i].size() > 0) {
      v.push_back(block(g[i][0], g[i].back(), i));
      last = g[i].back();
    }
  }
  v.push_back(block(n + 1, n + 1, 0x3f3f3f3f));
  for (int i = 0; i < 5; i++) {
    dp[0][i] = 0;
  }
  dp[0][0] = 1;
  solve(1);
  if (ok) {
    for (int i = 0; i < 5; i++) {
      int last = (int)v.size() - 2;
      int space = n - (v[last].end + i);
      if (dp[last][i] && space != 1) {
        get_ans(last, i);
        fill(v[last].val + 1, v[last].val + space / 2, v[last].end + i + 1, n);
        printf("%d\n", a[n]);
        for (int i = 1; i <= n; i++) {
          if (i != 1) {
            printf(" ");
          }
          printf("%d", a[i]);
        }
        printf("\n");
        return 0;
      }
    }
    printf("-1\n");
  } else {
    printf("-1\n");
  }
  return 0;
}
