#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

/* INCLUDE STATEMENTS */
#include <bits/stdc++.h>

/* NAMESPACES */
using namespace std; //  (┛ಠ_ಠ)┛  "Bad" Practice

/* ALIASES */
typedef long long lli;
typedef long double ld;
typedef unsigned uns;

typedef pair<int, int> pi;
typedef pair<lli, lli> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<lli> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

/* DEFINITIONS */
#define mp make_pair
#define pb push_back
#define F  first
#define S  second
#define lb lower_bound
#define ub upper_bound

#define fo(i, a, b) for(auto i=a; i<(b); i++)
#define forev(i, b, a) for(auto i = (b)-1; i >= a; i--)
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define sz(x) (int)x.size()
#define enl "\n"
#define deb(x) cout << #x << ": " << x << enl;

/* CONSTANTS */
// const ld PI = 4 * atan((ld)1);
// const int MOD = 1000000007;
// const lli INF = 1e18;
// const int MX = INT_MAX - 1;

/* UTILITIES */
template<typename T> bool _odd(T a) {return a & 1;}
template<typename T> bool _even(T a) {return !(a & 1);}

/*===========================================================================*/

void solve() {
    lli n, k; cin >> n >> k;
    vpl frn;
    fo(i, 0, n) {
        lli a, b; cin >> a >> b;
        frn.pb(mp(a, b));
    }
    sortall(frn);
    lli a = 0, c, d;
    fo(i, 0, n) {
        c = frn[i].F;
        d = frn[i].S;
        if ((c - a) > k) break;
        k -= (c - a);
        k += d;
        a = c;
    }
    cout << k + a;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int t = 1;
    // cin >> t;
    fo(i, 0, t) {
        solve();
    }
    return 0;
}
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

void solve(){
    ll N;
    cin >> N;
    vector<ll> P(N+1);
    rep(i,0,N) cin >> P[i];
    ll pos[200010] = {};
    rep(i,0,N){
        pos[P[i]] = i;
    }
    bool ok = true;
    vector<ll> ans;
    ll cur = 1;
    bool check[200010] = {};

    rep(t,0,N-1){
        while(cur <= N){
            if(pos[cur] != cur-1){
                break;
            }else{
                cur++;
            }
        }
        if(cur == N+1 || pos[cur] == 0 || check[pos[cur]-1] == true){
            ok = false;
            break;
        }
        // print(cur, pos[cur]);
        check[pos[cur]-1] = true;
        ans.push_back(pos[cur]-1 + 1);
        ll left_num = P[pos[cur]-1];
        swap(P[pos[cur]-1], P[pos[cur]]);
        pos[left_num] = pos[cur];
        pos[cur] = pos[cur]-1;
    }
    rep(i,1,N+1){
        if(P[i-1] != i) ok = false;
    }
    if(ok){
        for(auto &e: ans) print(e);
    }else{
        print(-1);
    }

}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
}