#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000 * 2 + 10;
int n, m, b[MAXN], d[MAXN][6], pre[MAXN][6];
pair<int, int> a[MAXN];
bool f[MAXN][6];
bool check(int n, int m) {
  if (m * 2 <= n && n <= m * 5) return true;
  return false;
}
void Print(int first, int k) {
  if (first == 1) return;
  int e = a[first].first;
  for (int i = a[first].first, j = k; j; --j, --i)
    b[i] = a[first].second, e = i;
  int s = a[first - 1].first + 1;
  for (int i = a[first - 1].first + 1, j = d[first][k]; j; --j, ++i, s = i)
    b[i] = a[first - 1].second;
  if (a[first].second - a[first - 1].second - 1 > 0) {
    int n = a[first].first - a[first - 1].first - k - d[first][k],
        m = a[first].second - a[first - 1].second - 1, c = n / m, r = n % m;
    int p = a[first - 1].second + 1;
    for (int i = 1; i <= r; ++i, ++p)
      for (int j = 1; j <= c + 1; ++j) b[s++] = p;
    for (; s < e; ++p)
      for (int j = 1; j <= c; ++j) b[s++] = p;
  }
  Print(first - 1, pre[first][k]);
}
int main() {
  a[++m] = make_pair(1, 1);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int first;
    cin >> first;
    if (first && i > 1) a[++m] = make_pair(i, first);
    if (i == 1 && first > 1) puts("-1"), exit(0);
    if (a[m].second < a[m - 1].second) puts("-1"), exit(0);
  }
  f[1][1] = 1;
  for (int i = 2; i <= m; ++i)
    for (int j = 1; j <= 5; ++j)
      if (f[i - 1][j])
        for (int k = 1; k <= 5; ++k)
          if (!f[i][k]) {
            if (a[i].second == a[i - 1].second) {
              if (j + a[i].first - a[i - 1].first == k)
                f[i][k] = 1, pre[i][k] = j;
              continue;
            }
            for (int l = 0; l + j <= 5; ++l)
              if (l + j >= 2)
                if (check(a[i].first - a[i - 1].first - l - k,
                          a[i].second - a[i - 1].second - 1))
                  f[i][k] = 1, pre[i][k] = j, d[i][k] = l;
          }
  bool flag = false;
  int Tohka;
  for (int i = 4; i >= 1; --i)
    if (f[m][i]) {
      flag = true;
      Tohka = i;
      Print(m, i);
      break;
    }
  if (!flag)
    if (f[m][5]) {
      flag = true;
      Tohka = 5;
      Print(m, 5);
    }
  if (!flag) puts("-1"), exit(0);
  if (Tohka == 5 && a[m].first + 1 == n) puts("-1"), exit(0);
  b[1] = 1;
  if (Tohka == 1 && a[m].first == n) puts("-1"), exit(0);
  if (Tohka == 1) b[a[m].first + 1] = a[m].second;
  for (int s = (Tohka == 1) + a[m].first + 1, j = a[m].second + 1; s <= n;
       s += 2, ++j)
    b[s] = b[s + 1] = j;
  b[n] = b[n - 1];
  cout << b[n] << endl;
  for (int i = 1; i <= n; ++i) printf("%d ", b[i]);
  puts("");
  fclose(stdin);
  fclose(stdout);
  return 0;
}
