#include <bits/stdc++.h>
using namespace std;
int n;
int a[200111];
pair<int, int> amin[200111];
pair<int, int> amax[200111];
int main() {
  cin >> n;
  amin[0] = make_pair(0, 4);
  amax[0] = make_pair(0, 1);
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; ++i) {
    if (a[i] != 0) {
      if (make_pair(a[i] - 1, 1) > amax[i - 1] ||
          make_pair(a[i], 3) < amin[i - 1]) {
        cout << -1 << endl;
        return 0;
      }
      if (amax[i - 1] >= make_pair(a[i], 3)) {
        amax[i] = make_pair(a[i], 4);
      } else if (amax[i - 1].first == a[i] - 1) {
        amax[i] = make_pair(a[i], 0);
      } else {
        amax[i] = amax[i - 1];
        ++amax[i].second;
      }
      if (amin[i - 1] <= make_pair(a[i] - 1, 4)) {
        amin[i] = make_pair(a[i], 0);
      } else {
        amin[i] = amin[i - 1];
        ++amin[i].second;
      }
    } else {
      amax[i] = amax[i - 1];
      ++amax[i].second;
      if (amax[i].second >= 2) {
        ++amax[i].first;
        ++amax[i].second = 0;
      }
      amin[i] = amin[i - 1];
      ++amin[i].second;
      if (amin[i].second == 5) {
        ++amin[i].first;
        ++amin[i].second = 0;
      }
    }
  }
  if (amax[n].second < 1) {
    if (amin[n].first == amax[n].first) {
      cout << -1 << endl;
      return 0;
    } else {
      --amax[n].first;
      amax[n].second = 4;
    }
  }
  for (int i = n - 1; i >= 1; --i) {
    pair<int, int> t = amax[i + 1];
    --t.second;
    if (t.second == -1) {
      --t.first;
      t.second = 4;
    }
    if (t < amax[i]) {
      amax[i] = t;
    }
  }
  cout << amax[n].first << endl;
  for (int i = 1; i < n; ++i) {
    cout << amax[i].first << ' ';
  }
  cout << amax[n].first << endl;
  return 0;
}
