#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define ll long long
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb push_back
#define pob pop_back()
#define Mod (ll)(1e9+7)
#define mod (ll)(998244353)
#define setp(x) setprecision((ll)(n))
#define INF (ll)(1000000000000000000)
using namespace std;
using vi=vector<int>;
using vc=vector<char>;
using vl=vector<long long>;
using vvi=vector<vi>;
using vvl=vector<vl>;
using vpl=vector<pair<ll,ll>>;
using vs=vector<string>;
using pii=pair<int, int>;
using pll=pair<ll,ll>;

int main(){
  ll n,k; cin>>n>>k;
  vpl p(n);
  rep(i,n) cin>>p[i].first>>p[i].second;
  sort(all(p));
  ll x=0;
  ll res,now;
  k-=p[0].first;
  if(k<0){
   cout<<k+p[0].first<<endl;
   return 0;
  }
  rep(i,n){
   k-=p[i].first-p[x].first;
   if(k<0){
     cout<<res<<endl;
     return 0;
   } else {
     k+=p[i].second;
     x=i;
     now=p[i].first;
     res=now+k;
   }
  }
  cout<<res<<endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    long long n, k;
    cin >> n >> k;
    vector<pair<long long, int>> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i].first >> v[i].second;
    }
    sort(v.begin(), v.end());
    for (auto [x, y] : v) {
        if (k >= x) {
            k += y;
        } else {
            break;
        }
    }
    cout << k << "\n";
    return 0;
}