#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using P = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve() {
  int n;
  cin >> n;
  vi a(n);
  rep(i, n) cin >> a[i];
  rep(i, n) a[i]--;
  dump(a);
  vi idx(n);
  rep(i, n) idx[a[i]] = i;
  dump(idx);
  int x = 0;
  vi ans;
  while (x < n - 1) {
    for (int i = idx[x] - 1; x <= i; i--) {
      if (i < 0 || n <= i + 1) {
        cout << -1 << endl;
        return;
      }
      swap(a[i], a[i + 1]);
      ans.push_back(i);
    }
    if (idx[x] <= x) {
      cout << -1 << endl;
      return;
    }
    x = idx[x];
  }
  dump(a);
  if (ans.size() != n - 1) {
    cout << -1 << endl;
    return;
  }
  rep(i, n) {
    if (a[i] != i) {
      cout << -1 << endl;
      return;
    }
  }
  rep(i, ans.size()) {
    cout << ans[i] + 1 << endl;
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(i64 i=0; i<n; i++)
#define all(v) v.begin(),v.end()
#define pp pair<int,int>
using Graph=vector<vector<int>>;
using i64=int64_t;

int main() {
    int n;cin>>n;
    vector<int>a(n);rep(i,n)cin>>a[i];
    i64 ans=0;
    rep(i,n) {
        ans+=max(0, a[i]-10);
    }
    cout << ans;
}