#include <bits/stdc++.h>
using namespace std;
vector<int> *solve() {
  int n;
  cin >> n;
  ;
  vector<int> a(n);
  {
    for (int i = 0; i < n; i++) cin >> a[i];
  };
  if (n == 1) return NULL;
  vector<int> mn(n);
  vector<int> mx(n);
  mn[0] = mx[0] = 10;
  if (a[0] > 1) {
    return NULL;
  }
  vector<int> noLarger(n);
  {
    int curMin = 100000;
    for (int i = n - 1; i >= 0; --i) {
      if (a[i] != 0) {
        if (a[i] > curMin) return NULL;
        curMin = a[i];
      }
      noLarger[i] = curMin;
    }
  }
  for (int i = 1; i < n - 1 + 1; ++i) {
    mn[i] = mn[i - 1] + 1;
    mx[i] = mx[i - 1] + 1;
    if (mx[i] % 10 >= 2 && mx[i] / 10 < noLarger[i]) mx[i] += 10 - mx[i] % 10;
    if (mn[i] % 10 >= 5) mn[i] += 10 - mn[i] % 10;
    if (mx[i] % 10 == 7) mx[i]--;
    if (a[i] != 0) {
      mx[i] = min(mx[i], a[i] * 10 + 4);
      mn[i] = max(mn[i], a[i] * 10 + 0);
      if (mx[i] < mn[i]) {
        return NULL;
      }
    }
  }
  vector<int> sol(n);
  int lastDigit = -1;
  for (int i = n - 1; i >= 0; --i)
    if (a[i] != 0) {
      lastDigit = i;
      break;
    }
  if (lastDigit != -1) {
    if (mx[lastDigit] % 10 == 4 && mn[lastDigit] % 10 < 4)
      sol[lastDigit] = mx[lastDigit] - 1;
    else
      sol[lastDigit] = mx[lastDigit];
    for (int i = lastDigit - 1; i >= 0; --i) {
      int nextDig = sol[i + 1];
      int curDig = nextDig % 10 == 0 ? nextDig - 6 : nextDig - 1;
      sol[i] = min(mx[i], curDig);
    }
    if (sol[lastDigit] % 10 == 0 && lastDigit + 1 < n) {
      sol[lastDigit + 1] = sol[lastDigit] + 1;
    }
  }
  int rem = 0;
  int fillWith = 1;
  for (int i = n - 1; i >= 0; --i)
    if (sol[i] == 0)
      rem++;
    else {
      fillWith = sol[i] / 10 + 1;
      break;
    }
  while (rem > 0) {
    if (rem == 1) {
      if (sol[n - rem - 1] % 10 < 4) {
        sol[n - rem] = sol[n - rem - 1] + 1;
        rem--;
      } else {
        return NULL;
      }
    } else {
      int x = 2;
      int startWith = n - rem;
      for (int i = 0; i < x - 1 + 1; ++i)
        sol[startWith + i] = fillWith * 10 + i;
      rem -= x;
      fillWith++;
    }
  }
  for (int i = 0; i < n - 1 + 1; ++i) sol[i] /= 10;
  if (sol.back() != sol[sol.size() - 2]) return NULL;
  return new vector<int>(sol);
}
int main() {
  ios_base::sync_with_stdio(false);
  vector<int> *sol = solve();
  if (sol == NULL) {
    cout << -1;
  } else {
    cout << sol->back() << '\n';
    for (int i = 0; i < sol->size() - 1 + 1; ++i) cout << sol->at(i) << ' ';
  }
}
