#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 10;
int an[MAX], n, ans[MAX];
struct Node {
  int pos;
  int num;
  int value;
  int left_znum;
  pair<int, int> valid_dist;
};
vector<Node> ns;
int main() {
  scanf("%d", &n);
  bool has_non_zero = 0;
  for (int i = (0); i < (n); ++i) {
    scanf("%d", &an[i]);
    if (an[i]) has_non_zero = 1;
  }
  if (an[0] > 1) {
    printf("%d\n", -1);
    return 0;
  }
  an[0] = 1;
  if (!has_non_zero) {
    if (n % 2 == 0) {
      for (int i = 0; i < n; i += 2) {
        int tmp = i / 2 + 1;
        ans[i] = ans[i + 1] = tmp;
      }
    } else {
      for (int i = 0; i < n - 1; i += 2) {
        int tmp = i / 2 + 1;
        ans[i] = ans[i + 1] = tmp;
      }
      ans[n - 1] = ans[n - 2];
    }
  } else {
    int znum = 0;
    bool ok = 1;
    for (int i = (0); i < (n); ++i) {
      if (!ok) break;
      if (an[i] == 0)
        znum += 1;
      else {
        Node nn;
        nn.num = 1, nn.left_znum = znum, nn.value = an[i], nn.pos = i;
        if (ns.size() == 0) {
          ns.push_back(nn);
        } else {
          auto& last = ns.back();
          if (last.value > nn.value) {
            ok = 0;
            break;
          } else if (last.value == nn.value) {
            last.num += znum + 1;
            if (last.num > 5) {
              ok = 0;
              break;
            }
          } else {
            ns.push_back(nn);
          }
        }
        znum = 0;
      }
    }
    if (!ok) {
      printf("%d\n", -1);
      return 0;
    }
    static auto inter = [](const pair<int, int>& a, const pair<int, int>& b) {
      return make_pair(max(a.first, b.first), min(a.second, b.second));
    };
    static auto valid = [](const pair<int, int>& a) {
      return a.first <= a.second;
    };
    for (int i = (0); i < (ns.size()); ++i) {
      if (i == 0) {
        int g = ns[i].left_znum + ns[i].num;
        ns[i].valid_dist = {2 - g, 5 - g};
        ns[i].valid_dist = inter(ns[i].valid_dist, {0, INT_MAX});
        if (!valid(ns[i].valid_dist)) {
          ok = 0;
          break;
        }
      } else {
        pair<int, int> tmp = ns[i - 1].valid_dist;
        int kale = ns[i].value - ns[i - 1].value - 1;
        tmp.first += 2 * kale, tmp.second += 5 * kale;
        tmp = inter({ns[i].left_znum - tmp.second, ns[i].left_znum - tmp.first},
                    {0, INT_MAX});
        if (!valid(tmp)) {
          ok = 0;
          break;
        }
        tmp.first += ns[i].num, tmp.second += ns[i].num;
        tmp = make_pair(2 - tmp.second, 5 - tmp.first);
        tmp = inter(tmp, {0, INT_MAX});
        if (!valid(tmp)) {
          ok = 0;
          break;
        }
        ns[i].valid_dist = tmp;
      }
    }
    if (!ok) {
      printf("%d\n", -1);
      return 0;
    }
    int last_resi = n - ns.back().pos - ns.back().num;
    auto end = inter(ns.back().valid_dist, {0, last_resi});
    if (!valid(end)) {
      printf("%d\n", -1);
      return 0;
    }
    int pre_select = end.first;
    int resi = last_resi - end.first;
    if (resi == 1) {
      if (end.second == end.first) {
        printf("%d\n", -1);
        return 0;
      } else {
        pre_select = end.first + 1;
        --resi;
      }
    }
    int start_value = ns.back().value + 1;
    for (int i = n - resi; i < n; i += 2) {
      ans[i] = ans[i + 1] = start_value++;
    }
    if (resi % 2 == 1) {
      ans[n - 1] = ans[n - 2];
    }
    for (int i = ((int)ns.size() - 1); i >= (0); --i) {
      auto& nn = ns[i];
      int pos = nn.pos, num = nn.num + pre_select;
      while (num--) ans[pos++] = nn.value;
      if (i > 0) {
        int total = pre_select + nn.num;
        auto B1 = make_pair(max(2 - total, 0), 5 - total);
        assert(B1.first >= 0 && B1.second >= 0);
        vector<int> len_seq;
        len_seq.push_back(ns[i - 1].valid_dist.first);
        int diff = ns[i].value - ns[i - 1].value;
        for (int j = (1); j <= (diff - 1); ++j) {
          len_seq.push_back(2);
        }
        len_seq.push_back(B1.first);
        total = 0;
        for (int j = (0); j < (len_seq.size()); ++j) {
          total += len_seq[j];
        }
        int resi =
            (ns[i].pos - 1 - (ns[i - 1].pos + ns[i - 1].num) + 1) - total;
        int pos = 0;
        pre_select = ns[i - 1].valid_dist.first;
        while (pos < len_seq.size() && resi) {
          int limit;
          if (pos == 0)
            limit = ns[i - 1].valid_dist.second;
          else if (pos == (int)len_seq.size() - 1)
            limit = B1.second;
          else
            limit = 5;
          int use = min(resi, limit - len_seq[pos]);
          resi -= use;
          len_seq[pos] += use;
          if (pos == 0) {
            pre_select = len_seq[pos];
          }
          ++pos;
        }
        int start = ns[i - 1].value + 1;
        pos = ns[i - 1].pos + ns[i - 1].num + len_seq[0];
        for (int j = (1); j < (len_seq.size()); ++j) {
          while (len_seq[j]--) {
            ans[pos++] = start;
          }
          ++start;
        }
      } else {
        for (int j = (0); j < (nn.pos); ++j) {
          ans[j] = 1;
        }
      }
    }
  }
  printf("%d\n", ans[n - 1]);
  for (int i = (0); i < (n); ++i) printf("%d ", ans[i]);
  printf("\n");
  return 0;
}
