#include <bits/stdc++.h>
using namespace std;
class BLOCK {
 public:
  int elem;
  int numElem;
  int numZero;

 public:
  BLOCK(int _elem = 0, int _numElem = 0, int _numZero = 0) {
    elem = _elem;
    numElem = _numElem;
    numZero = _numZero;
  }
};
int n;
vector<int> note;
vector<BLOCK> block;
vector<vector<bool> > toLeft, toRight;
vector<int> ans;
int GetTruePos(vector<bool>& v, int up) {
  for (int i = 0; i < up; ++i)
    if (v[i]) return i;
  return -1;
}
bool Work() {
  block.clear();
  block.push_back(BLOCK(0, 0, 0));
  for (int i = 0; i < n; ++i) {
    if (!note[i]) {
      block.back().numZero++;
    } else {
      if (note[i] != block.back().elem) {
        block.push_back(BLOCK(note[i], 1, 0));
      } else {
        block.back().numElem += block.back().numZero + 1;
        block.back().numZero = 0;
      }
    }
  }
  toLeft.assign(block.size(), vector<bool>(5, false));
  toRight.assign(block.size(), vector<bool>(5, false));
  toRight[0][0] = true;
  for (int i = 1; i < int(block.size()); ++i) {
    for (int l = 0; l < 5; ++l) {
      if (l + block[i].numElem > 5) continue;
      for (int r = 0; r < 5 && !toLeft[i][l]; ++r) {
        if (!toRight[i - 1][r]) continue;
        if (r + l <= block[i - 1].numZero) {
          int zeros = block[i - 1].numZero - l - r;
          int diff = block[i].elem - block[i - 1].elem;
          diff -= 1;
          if (zeros >= diff * 2 && zeros <= diff * 5) {
            toLeft[i][l] = true;
          }
        }
      }
    }
    bool terminal = false;
    for (int r = 0; r < 5; ++r) {
      if (r > block[i].numZero) continue;
      for (int l = 0; l < 5 && !toRight[i][r]; ++l) {
        if (!toLeft[i][l]) continue;
        int num = r + l + block[i].numElem;
        if (num >= 2 && num <= 5) {
          toRight[i][r] = true;
          terminal = true;
        }
      }
    }
    if (!terminal) return false;
  }
  int size = int(block.size());
  int remain = block.back().numZero - GetTruePos(toRight[size - 1], 5);
  ans.clear();
  if (remain == 1)
    ans.push_back(block.back().elem);
  else if (remain > 1) {
    int val = block.back().elem + 1;
    if (remain & 1) {
      ans.push_back(val);
      --remain;
    }
    for (int i = 1; i <= remain; ++i) {
      ans.push_back(val);
      if (!(i & 1)) ++val;
    }
    reverse(ans.begin(), ans.end());
  }
  int rj = GetTruePos(toRight[size - 1], 5);
  for (int i = size - 1; i > 0; --i) {
    int lj = 0;
    while (lj < 5) {
      int temp = block[i].numElem + lj + rj;
      if (toLeft[i][lj] && temp >= 2 && temp <= 5) break;
      ++lj;
    }
    int num = lj + rj + block[i].numElem;
    for (int k = 0; k < num; ++k) ans.push_back(block[i].elem);
    int zeros;
    int numVal = block[i].elem - block[i - 1].elem - 1;
    rj = 0;
    while (rj < 5) {
      if (toRight[i - 1][rj]) {
        zeros = block[i - 1].numZero - lj - rj;
        if (zeros >= numVal * 2 && zeros <= numVal * 5) {
          break;
        }
      }
      ++rj;
    }
    if (!numVal) continue;
    vector<int> temp;
    int m = zeros / numVal, re = zeros % numVal;
    int val = block[i - 1].elem + 1;
    for (int k = 1; k <= numVal; ++k) {
      for (int j = 0; j < m; ++j) temp.push_back(val);
      if (k <= re) temp.push_back(val);
      ++val;
    }
    reverse(temp.begin(), temp.end());
    ans.insert(ans.end(), temp.begin(), temp.end());
  }
  reverse(ans.begin(), ans.end());
  cout << ans.back() << endl;
  for (int i = 0; i < int(ans.size()); ++i) cout << ans[i] << " ";
  cout << endl;
  return true;
}
int main() {
  ios::sync_with_stdio(false);
  while (cin >> n) {
    note.resize(n);
    for (int i = 0; i < n; ++i) cin >> note[i];
    if (!Work()) cout << -1 << endl;
  }
  return 0;
}
