#include <bits/stdc++.h>
using namespace std;
int n;
int a[1000000];
int antle[1000000][5], antri[1000000][5];
struct triple {
  int x, nx, n0;
  triple() {}
  triple(int inx, int innx, int inn0) {
    x = inx;
    nx = innx;
    n0 = inn0;
  }
};
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<triple> v;
  v.push_back(triple(0, 0, 0));
  for (int i = 0; i < n; i++) {
    if (a[i] == 0)
      v.back().n0++;
    else if (a[i] == v.back().x) {
      v.back().nx++;
      v.back().nx += v.back().n0;
      v.back().n0 = 0;
      if (v.back().nx > 5) {
        cout << -1 << endl;
        exit(0);
      }
    } else {
      if (a[i] < v.back().x) {
        cout << -1 << endl;
        exit(0);
      }
      v.push_back(triple(a[i], 1, 0));
    }
  }
  antri[0][0] = 0;
  for (int j = 1; j < 5; j++) antri[0][j] = -1;
  for (int i = 1; i < int(v.size()); i++) {
    for (int j = 0; j < 5; j++) {
      antle[i][j] = -1;
      if (j + v[i].nx <= 5 and j <= v[i - 1].n0)
        for (int jj = 0; jj < 5 and antle[i][j] == -1; jj++)
          if (antri[i - 1][jj] >= 0 and j + jj <= v[i - 1].n0 and
              (v[i].x - v[i - 1].x - 1) * 2 <= v[i - 1].n0 - (j + jj) and
              (v[i].x - v[i - 1].x - 1) * 5 >= v[i - 1].n0 - (j + jj))
            antle[i][j] = jj;
    }
    for (int j = 0; j < 5; j++) {
      antri[i][j] = -1;
      if (j <= v[i].n0 and j + v[i].nx <= 5)
        for (int jj = 0; jj < 5 and antri[i][j] == -1; jj++)
          if (antle[i][jj] >= 0 and j + jj + v[i].nx <= 5 and
              j + jj + v[i].nx >= 2)
            antri[i][j] = jj;
    }
  }
  for (int j = 0; j < 5; j++) {
    if (antri[int(v.size()) - 1][j] >= 0 and
        (v.back().n0 - j == 0 or v.back().n0 - j >= 2)) {
      vector<int> sol;
      if ((v.back().n0 - j) % 2 == 0)
        for (int i = 0; i < v.back().n0 - j; i++)
          sol.push_back(v.back().x + (v.back().n0 - j) / 2 - i / 2);
      else {
        for (int i = 0; i < v.back().n0 - j - 1; i++)
          sol.push_back(v.back().x + (v.back().n0 - j) / 2 - i / 2);
        sol.push_back(v.back().x + 1);
      }
      for (int i = int(v.size()) - 1; i > 0; i--) {
        for (int k = 0; k < j; k++) sol.push_back(v[i].x);
        for (int k = 0; k < v[i].nx; k++) sol.push_back(v[i].x);
        j = antri[i][j];
        for (int k = 0; k < j; k++) sol.push_back(v[i].x);
        int nextj = antle[i][j];
        int espacio = v[i - 1].n0 - j - nextj;
        for (int k = 0; k < v[i].x - v[i - 1].x - 1; k++) {
          for (int p = 0; p < espacio / (v[i].x - v[i - 1].x - 1); p++)
            sol.push_back(v[i].x - 1 - k);
          if (k < espacio % (v[i].x - v[i - 1].x - 1))
            sol.push_back(v[i].x - 1 - k);
        }
        j = nextj;
      }
      reverse(sol.begin(), sol.end());
      cout << sol.back() << endl;
      for (int i = 0; i < int(sol.size()); i++) {
        if (i > 0) cout << " ";
        cout << sol[i];
      }
      cout << endl;
      exit(0);
    }
  }
  cout << -1 << endl;
}
