#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int a[200007];
  for (int i = (0); i < (N); i++) cin >> a[i];
  int mnb[200007], mnd[200007], mxb[200007], mxd[200007];
  int rb[200007], rd[200007];
  mnb[0] = mnd[0] = mxb[0] = mxd[0] = 1;
  if (a[0] > 1) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = (1); i < (N); i++) {
    mnb[i] = mnb[i - 1];
    mxb[i] = mxb[i - 1];
    mnd[i] = mnd[i - 1] + 1;
    mxd[i] = mxd[i - 1] + 1;
    if (mnd[i] > 5) {
      mnb[i]++;
      mnd[i] = 1;
    }
    if (mxd[i] > 2) {
      mxb[i]++;
      mxd[i] = 1;
    }
    if (a[i] != 0) {
      if (a[i] < mnb[i]) {
        cout << -1 << endl;
        return 0;
      }
      if (a[i] > mxb[i]) {
        cout << -1 << endl;
        return 0;
      }
      if (a[i] > mnb[i]) {
        mnb[i] = a[i];
        mnd[i] = 1;
      }
      if (a[i] < mxb[i]) {
        mxb[i] = a[i];
        mxd[i] = 5;
      }
    }
  }
  if (mnb[N - 1] == mxb[N - 1] && mnd[N - 1] == 1 && mxd[N - 1] == 1) {
    cout << -1 << endl;
    return 0;
  }
  if (mxd[N - 1] == 1) {
    rb[N - 1] = mxb[N - 1] - 1;
    rd[N - 1] = 2;
    if (rb[N - 1] == mnb[N - 1] && mnd[N - 1] > rd[N - 1])
      rd[N - 1] = mnd[N - 1];
  } else {
    rb[N - 1] = mxb[N - 1];
    rd[N - 1] = mxd[N - 1];
  }
  for (int i = (N - 2); i >= (0); i--) {
    rb[i] = rb[i + 1];
    rd[i] = rd[i + 1] - 1;
    if (rd[i] == 0) {
      rb[i]--;
      rd[i] = 5;
    }
    if (mxb[i] == rb[i] && mxd[i] < rd[i]) rd[i] = mxd[i];
  }
  cout << rb[N - 1] << endl;
  for (int i = (0); i < (N); i++) cout << rb[i] << " ";
  cout << endl;
  return 0;
}
