#include <bits/stdc++.h>
#include <variant>

#define rep2(i,k,n) for(i64 i=(i64)(k);i<(i64)(n);i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) begin(x),end(x)
#ifdef ENV_LOCAL
#define dump if (1) cerr
#else
#define dump if (0) cerr
#endif

using namespace std;
using namespace std::string_literals;

using i32 = int32_t;
using i64 = int64_t;
using f64 = double;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;

//using namespace harudake;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  i64 n,k;
  cin>>n>>k;
  vector<tuple<i64,i64>> vt;
  rep(i,n) {
    i64 a,b;
    cin>>a>>b;
    vt.emplace_back(a,b);
  }
  vt.emplace_back(0,k);
  vt.emplace_back(1'000'000'000'000'000,0);
  sort(all(vt));
  i64 sum = 0;
  i64 pos = 0;
  rep(i,n+1) {
    auto[a0,b0] = vt[i];
    auto[a1,b1] = vt[i+1];
    sum += b0;
    i64 d = a1 - a0;
    if (sum < d) break;
    pos = a1;
    sum -= d;
  }
  pos += sum;
  cout<<pos<<endl;
  return 0;
}


#include<bits/stdc++.h>
#define ulli unsigned long long int
using namespace std;
int main()
{
    ulli n,k;
    cin>>n>>k;
    vector<pair<ulli,ulli>>v;
    for(int i = 0;i<n;i++)
    {
        ulli a,b;
        cin>>a>>b;
        v.push_back({a,b});
    }
    sort(v.begin(),v.end());
    for(int i = 0;i<n;i++)
    {
        if(v[i].first > k)
            break;
        k += v[i].second;
    }
    cout<<k;
}
