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

int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,k;
    cin>>n>>k;
    vector<pair<int,int>>v(n);
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        v[i].first=a;
        v[i].second=b;
    }
    sort(v.begin(),v.end());
    for(int i=0;i<n;i++){
        if(k>=v[i].first) k+=v[i].second;
        else break;
    }
    cout<<k;
    return 0;
}
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 1; i <= (n); ++i)
#define debug(a) cout << #a << " = " << a << endl;
using namespace std;
typedef long long ll;
int main()
{
    ll n, now; cin >> n >> now;
    
    map<ll, ll> mp;
    rep(i, n) {
        ll a, b; scanf("%lld %lld", &a, &b);
        mp[a] += b;
    }
    
    for (auto& [a, b] : mp) {
        if (a <= now) now += b;
        else break;
    }
    cout << now << endl;
    return 0;
}
