#include <bits/stdc++.h>
#define int long long
#define menhera_chan_is_mine ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define pi pair<int, int>
#define BE(i) i.begin(),i.end()
#define fi first
#define se second
#define INF 2147483647
#define mkp make_pair
#define ist insert
#define mod 1000000007
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
//#pragma GCC optimize("O2")
using namespace std;
int min(int a, int b){return a < b ? a : b;}
int max(int a, int b){return a > b ? a : b;}
bool isprime(int k){bool is=1 ; for ( int i = 2 ; i*i <= k ; i++ ) if ( k % i == 0 ) is = 0 ; return k>1?is:0;}
const double PI=acos(-1);
int n,k;
pi a[200005];
void sol(){
    cin >>n>>k;
    for (int i=0;i<n;i++) cin >>a[i].fi>>a[i].se;
    sort(a,a+n);
    for (int i=0;i<n;i++){
        if (k>=a[i].fi) k+=a[i].se;
    }
    cout <<k<<"\n";
}
signed main(){
    menhera_chan_is_mine
    int _=1;
    //cin >>_;
    while (_--) sol();
    return 0;
}

#include<iostream>
#include<climits>
#include<bits/stdc++.h>
using namespace std;
#define LL long long int
#define mod 998244353
LL r(vector<LL> &kabza,vector<LL> &nonKabza,LL i,LL j,vector<vector<LL> > &dp){
    if( i>=kabza.size() ){
        return 0;
    }
    if (j>=nonKabza.size()){
        return INT_MAX;
    }
    LL &ans= dp[i][j];
    if(ans != -1){
        return ans;
    }
    return ans = min( r(kabza,nonKabza,i,j+1,dp) , r(kabza,nonKabza,i+1,j+1,dp) + abs(kabza[i]-nonKabza[j]));
}

int main() 
{
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    LL N,K;
    cin >> N >> K;
    map <LL,LL> hash;
    for(LL i=0;i<N;i++){
        LL x,y;
        cin >> x >> y;
        hash[x]+=y;
    }
    LL have= K;
    LL pos = 0;
    for(auto it:hash){
        LL reach= have+pos;
        if(reach<it.first){
            break;
        }
        have= have-(it.first - pos);
        have+= it.second;
        pos= it.first;
    }
    cout<<have+pos;
}

