#include <bits/stdc++.h>
using namespace std;
 
const int N = 200005;
 
int n;
int a[N];
int pos[N];
bool used[N];

int solve() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    pos[--a[i]] = i;
    used[i] = false;
  }

  vector<int> ans;
  for (int i = n - 1; i > 0; --i) {
    while (pos[i] != i) {
      if (used[pos[i]]) return 0 * printf("-1\n");
      int p = pos[i];
      swap(pos[i], pos[a[p + 1]]);
      swap(a[p], a[p + 1]);
      ans.push_back(p);
      used[p] = true;
    }
  }

  if (ans.size() != n - 1) return 0 * printf("-1\n");
  for (int u : ans) printf("%d\n", u + 1);

  return 0;
}

int main() {
  int t = 1;
  // scanf("%d", &t);
  for (int tc = 0; tc < t; ++tc) {
    // printf("Case #%d: ", tc+1);
    solve();
  }
  return 0;
}

#include <iostream>
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ll long long
#define forn(i,a,n,b) for(ll i=a;i<n;i+=b)
#define forr(i,a,n,b) for(ll i=a;i>=n;i-=b)
#define MOD 1000000007
#define vll vector<ll>
using namespace std;

int main()
{
    fastio;
    ll t = 1;
    // cin>>t;
    while(t-->0)
    {
        ll n, takahoshi = 0, ans = 0;
        cin>>n;
        vector<pair<ll, pair<ll, ll>>> pairs;
        forn(i,0,n,1)
        {
            ll a, b;
            cin>>a>>b;
            pairs.emplace_back(2*a+b, make_pair(a,b));
            takahoshi -= a;
        }
        sort(pairs.begin(), pairs.end());
        forr(i,n-1,0,1)
        {
            takahoshi += pairs[i].first;
            ans++;
            if (takahoshi > 0)
            {
                break;
            }
        }
        cout<<ans<<"\n";
    }
    return 0;
}


