#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const int MIN_L = 2;
const int MAX_L = 5;
int N, MaxIndex;
vector<int> Left, Right, Solution;
bool Possible;
void Solve() {
  Possible = true;
  vector<int> previous = vector<int>(MaxIndex + 1, -1);
  for (int i = 1, p = 0; i <= MaxIndex && Possible; ++i) {
    if (Left[i] != -1 &&
        (Right[i] - Left[i] + 1 > MAX_L || (p != 0 && Left[i] <= Right[p])))
      Possible = false;
    if (Left[i] != -1) {
      previous[i] = p;
      p = i;
    }
  }
  if (!Possible) return;
  vector<vector<bool> > dp =
      vector<vector<bool> >(MaxIndex + 1, vector<bool>(MAX_L, false));
  dp[0][0] = true;
  for (int i = 1; i <= MaxIndex; ++i) {
    if (Left[i] == -1) continue;
    int j = previous[i];
    for (int l = 0; l < MAX_L && Right[i] + l < N; ++l) {
      int end = Right[i] + l, begin = min(Left[i], Right[i] + l + 1 - MIN_L);
      if (end - begin + 1 > MAX_L) continue;
      for (; end - begin + 1 <= MAX_L && !dp[i][l]; --begin) {
        for (int prevl = 0; prevl < MAX_L && !dp[i][l]; ++prevl) {
          int prevEnd = Right[j] + prevl;
          if (prevEnd >= begin) continue;
          int space = begin - prevEnd - 1, toFill = i - j - 1;
          int minSpace = MIN_L * toFill, maxSpace = MAX_L * toFill;
          if (space < minSpace || maxSpace < space) continue;
          if (dp[j][prevl]) dp[i][l] = true;
        }
      }
    }
  }
  int lastl = 0;
  for (; lastl < MAX_L && !dp[MaxIndex][lastl]; ++lastl)
    ;
  if (lastl == MAX_L) {
    Possible = false;
    return;
  }
  Solution = vector<int>(N, 0);
  for (int i = MaxIndex, l = lastl; i > 0; i = previous[i]) {
    int j = previous[i];
    int end = Right[i] + l, begin = min(Left[i], Right[i] + l + 1 - MIN_L);
    int fatherL = -1;
    for (; end - begin + 1 <= MAX_L && fatherL == -1; --begin) {
      for (int prevl = 0; prevl < MAX_L && fatherL == -1; ++prevl) {
        int prevEnd = Right[j] + prevl;
        if (prevEnd >= begin) continue;
        int space = begin - prevEnd - 1, toFill = i - j - 1;
        int minSpace = MIN_L * toFill, maxSpace = MAX_L * toFill;
        if (space < minSpace || maxSpace < space) continue;
        if (dp[j][prevl]) {
          for (int k = prevEnd + 1, index = j + 1; k < begin; ++index) {
            bool found = false;
            for (int currentL = MIN_L; !found; ++currentL) {
              int newSpace = space - currentL, newToFill = toFill - 1;
              int newMinSpace = MIN_L * newToFill,
                  newMaxSpace = MAX_L * newToFill;
              if (newSpace < newMinSpace || newMaxSpace < newSpace) continue;
              found = true;
              for (; currentL > 0; --currentL, ++k) Solution[k] = index;
              space = newSpace;
              toFill = newToFill;
            }
          }
          fatherL = prevl;
        }
      }
      for (int k = begin; k <= end; ++k) Solution[k] = i;
    }
    l = fatherL;
  }
  for (int i = Right[MaxIndex] + lastl + 1, index = MaxIndex + 1; i + 1 < N;
       i += 2)
    Solution[i] = Solution[i + 1] = index++;
  if (Solution[N - 1] == 0) Solution[N - 1] = Solution[N - 2];
}
void Read() {
  cin >> N;
  MaxIndex = 0;
  Left = Right = vector<int>(1, -1);
  for (int i = 0; i < N; ++i) {
    int index;
    cin >> index;
    if (index == 0) continue;
    MaxIndex = max(MaxIndex, index);
    if (index >= int(Left.size())) {
      Left.resize(index + 1, -1);
      Right.resize(index + 1, -1);
    }
    if (Left[index] == -1) Left[index] = i;
    Right[index] = i;
  }
}
void Print() {
  if (!Possible) {
    cout << "-1\n";
    return;
  }
  cout << Solution[N - 1] << "\n";
  for (int i = 0; i < N; ++i) cout << Solution[i] << " ";
  cout << "\n";
}
int main() {
  Read();
  Solve();
  Print();
  return 0;
}
