#include <bits/stdc++.h>
using namespace std;
const int n_max = 200003;
int a[n_max], ans, i, j, n, cur, x;
int par[n_max], l;
pair<int, int> dp[n_max][7];
pair<int, int> P;
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 1; i < 5; i++) dp[0][i] = make_pair(1, 0);
  dp[0][5] = make_pair(0, 0);
  for (i = 1; i <= n; i++) {
    P = make_pair(10000000, 0);
    for (j = 2; j <= 5; j++) {
      if (dp[i - 1][j].first <= dp[i - 1][j].second)
        P.first = (P.first < dp[i - 1][j].first + 1 ? P.first
                                                    : dp[i - 1][j].first + 1),
        P.second =
            (P.second > dp[i - 1][j].second + 1 ? P.second
                                                : dp[i - 1][j].second + 1);
      if (a[i])
        P.first = (P.first > a[i] ? P.first : a[i]),
        P.second = (P.second < a[i] ? P.second : a[i]);
    }
    dp[i][1] = P;
    for (j = 2; j <= 5; j++) {
      dp[i][j] = dp[i - 1][j - 1];
      if (a[i])
        dp[i][j].first = (dp[i][j].first > a[i] ? dp[i][j].first : a[i]),
        dp[i][j].second = (dp[i][j].second < a[i] ? dp[i][j].second : a[i]);
    }
  }
  ans = -1;
  for (i = 2; i < 6; i++)
    if (dp[n][i].first <= dp[n][i].second)
      if (dp[n][i].second >= ans) ans = dp[n][i].second, l = i;
  if (ans == -1) {
    printf("-1\n");
    return 0;
  }
  x = n;
  cur = ans;
  while (x > 0) {
    for (i = x; i > x - l; i--) a[i] = cur;
    cur--;
    x -= l;
    for (i = 2; i < 6; i++)
      if (dp[x][i].first <= cur && dp[x][i].second >= cur) {
        l = i;
        break;
      }
  }
  cout << ans << endl;
  for (i = 1; i <= n; i++) cout << a[i] << ' ';
  cout << endl;
}
