#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
const int INF = 2e9;
const long long LINF = 9e18;
const int MOD1 = 2e9 + 11;
const int MOD2 = 1e9 + 9;
const int MOD3 = 1e9 + 7;
const int p = 37;
const int MAXN = 2e5 + 10;
pii dp[MAXN];
int vis[MAXN], A[MAXN], n;
pii rec(int idx) {
  if (idx == 0) return pii(0, 0);
  if (idx == 1) return pii(INF, -1);
  if (vis[idx]) return dp[idx];
  vis[idx] = 1;
  int num = 0;
  dp[idx] = pii(INF, -1);
  for (int j = idx, len = 1; len <= 5 && j >= 1; len++, j--) {
    if (A[j] != 0) {
      if (num != 0 && A[j] != num)
        break;
      else {
        num = A[j];
      }
    }
    if (len == 1) continue;
    dp[j - 1] = rec(j - 1);
    if (dp[j - 1].first == INF) continue;
    int l = INF, r = -1;
    if (num == 0) {
      l = dp[j - 1].first + 1, r = dp[j - 1].second + 1;
    } else if (dp[j - 1].first <= num - 1 && num - 1 <= dp[j - 1].second) {
      l = r = num;
    }
    dp[idx].first = min(dp[idx].first, l);
    dp[idx].second = max(dp[idx].second, r);
  }
  return dp[idx];
}
void print(int idx, int num) {
  if (num == 0) return;
  for (int j = idx, len = 1; j >= 1 && len <= 5; len++, j--) {
    if (len == 1) continue;
    if (dp[j - 1].first <= num - 1 && num - 1 <= dp[j - 1].second) {
      print(j - 1, num - 1);
      while (len--) {
        printf("%d ", num);
      }
      return;
    }
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> A[i];
  pii ret = rec(n);
  cout << ret.second << endl;
  if (ret.second != -1) {
    print(n, ret.second);
    cout << endl;
  }
  return 0;
}
