#include <bits/stdc++.h>
using namespace std;
struct node {
  int id;
  int s, e;
  node(){};
  node(int ID, int ss, int ee) : id(ID), s(ss), e(ee){};
};
int N;
int a[200010];
vector<node> where[200010];
vector<int> from[200010];
int main() {
  while (scanf("%d", &N) != EOF) {
    vector<node> num;
    int siz = 0;
    bool flag = true;
    for (int i = 0; i < N; i++) {
      scanf("%d", &a[i]);
      if (a[i] != 0) {
        if (siz > 0 && num[siz - 1].id == a[i]) {
          num[siz - 1].e = i;
          if (num[siz - 1].e - num[siz - 1].s > 4) flag = false;
        } else {
          if (siz > 0 && num[siz - 1].id > a[i]) flag = false;
          num.push_back(node(a[i], i, i));
          siz++;
        }
      }
    }
    if (flag == false) {
      printf("-1\n");
      continue;
    }
    for (int i = 0; i <= siz; i++) {
      where[i].clear();
      from[i].clear();
    }
    where[0].push_back(node(0, -1, -1));
    from[0].push_back(-1);
    for (int i = 0; i < siz; i++) {
      int is = num[i].s, ie = num[i].e, ix = num[i].id;
      int nn = where[i].size();
      for (int j = 0; j < nn; j++) {
        int iv = where[i][j].id;
        int ed = where[i][j].e;
        for (int pre = -4; pre <= 0; pre++)
          for (int suf = 0; suf <= 4; suf++) {
            int ss = is + pre, ee = ie + suf;
            if (ee - ss < 1 || ee >= N) continue;
            if (ee - ss > 4) break;
            int diff = ss - ed - 1;
            if (diff < 0) continue;
            if (diff >= (ix - iv - 1) * 2 && diff <= (ix - iv - 1) * 5) {
              bool has = false;
              for (int kk = 0; kk < where[i + 1].size(); kk++)
                if (where[i + 1][kk].e == ee) has = true;
              if (!has) {
                where[i + 1].push_back(node(ix, ss, ee));
                from[i + 1].push_back(j);
              }
            }
          }
      }
      if (where[i + 1].size() == 0) {
        flag = false;
        break;
      }
    }
    if (!flag) {
      printf("-1\n");
      continue;
    }
    int bestend = 1000000000;
    int bestid = -1;
    for (int i = 0; i < where[siz].size(); i++) {
      if (where[siz][i].e < bestend && N - where[siz][i].e != 2) {
        bestend = where[siz][i].e;
        bestid = i;
      }
    }
    if (bestid == -1) {
      printf("-1\n");
      continue;
    }
    int nowid = bestid;
    for (int i = siz; i > 0; i--) {
      for (int j = where[i][bestid].s; j <= where[i][bestid].e; j++)
        a[j] = where[i][bestid].id;
      int preid = from[i][bestid];
      int tid = where[i][bestid].id, sid = where[i - 1][preid].id;
      if (sid + 1 != tid) {
        int ave =
            (where[i][bestid].s - where[i - 1][preid].e - 1) / (tid - sid - 1);
        int mod =
            (where[i][bestid].s - where[i - 1][preid].e - 1) % (tid - sid - 1);
        int pos = where[i - 1][preid].e + 1;
        for (int idd = sid + 1; idd < tid; idd++) {
          if (mod) {
            for (int kk = 0; kk <= ave; kk++) a[pos++] = idd;
            mod--;
          } else
            for (int kk = 0; kk < ave; kk++) a[pos++] = idd;
        }
      }
      bestid = preid;
    }
    int left = N - where[siz][nowid].e - 1;
    int ans;
    if (left != 0) {
      ans = where[siz][nowid].id + left / 2;
      int addnum = left / 2;
      int pos = where[siz][nowid].e + 1, idd = where[siz][nowid].id + 1;
      if (left & 1) a[pos++] = idd;
      for (; idd <= ans; idd++) {
        a[pos++] = idd;
        a[pos++] = idd;
      }
    } else
      ans = where[siz][nowid].id;
    printf("%d\n", ans);
    for (int i = 0; i < N; i++) printf("%d ", a[i]);
    printf("\n");
  }
  return 0;
}
