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

#define endl        "\n"
#define LL          long long
#define READ        freopen("in.txt","r",stdin)
#define WRITE       freopen("out.txt","w",stdout)
#define BOOST       ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb          push_back
#define mem(x,y)    memset(x,y,sizeof x )
#define ch          printf("Came Here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n")
#define deb(x)      cerr<<#x<<" :: "<<x<<" "
#define dnl         cerr<<endl;
#define FOR(i,n)    for(int i=0;i<n;i++)
#define cnd         tree[idx]
#define lc          tree[idx*2]
#define rc          tree[idx*2+1]
#define lnd         (2*idx),(b),( (b+e) /2 )
#define rnd         ((2*idx)+1),(((b+e)/2)+1),(e)
#define popcountL   __builtin_popcountll
#define popcount    __builtin_popcount


const LL        INF = 1LL<<59;
const double    PI = 2.0 * acos(0.0);

typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

////// Including Policy Based DS
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//
/////cout<<*X.find_by_order(1)<<endl;
/////cout<<X.order_of_key(-5)<<endl;
//typedef tree<
//LL,
//null_type,
//less< pll >,
//rb_tree_tag,
//tree_order_statistics_node_update>
//ordered_set;

// graph direction array [4]
int X[4]={0,0,-1,1};
int Y[4]={1,-1,0,0};
// graph direction array [8]
//int X[8]={0,0,1,-1,-1,1,1,-1};
//int Y[8]={1,-1,0,0,-1,-1,1,1};
// Bishop direction array [8]
//int BX[8]={0,0,1,-1,-1,1,1,-1};
//int BY[8]={1,-1,0,0,-1,-1,1,1};
// Knight Direction Array
//int KX[8] = {1,1,2,2,-1,-1,-2,-2};
//int KY[8] = {2,-2,1,-1,2,-2,1,-1};

inline bool checkBit(int N,int pos){return (bool)(N & (1<<pos));}
inline int setBit(int N,int pos){ return N=N | (1<<pos);}
inline int unsetBit(int N,int pos){ return N=( N & ( ~( 1<<pos ) ) );}
inline int toggleBit(int N,int pos){ return N = ( N ^(1<<pos) ); }

inline LL modMul(LL a, LL b,LL mod){
    LL ans = 0;
    a = a % mod;
    while (b > 0){
        if ( b % 2 )ans = (ans%mod+ a%mod) % mod;
        a = (a%mod * 2%mod) % mod;
        b /= 2;
    }
    return ans % mod;
}
inline LL powerMod(LL a,LL b,LL mod){
    if(b==0)return 1LL%mod;
    LL x=powerMod( a,b/2,mod );
    x = modMul(x,x,mod) % mod;
    if( b%2==1 )x = modMul(x,a,mod) % mod;
    return x%mod;
}
inline LL lcm( LL a,LL b ){
    LL g = __gcd(a,b);
    return ((a/g) * b);
}

//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
const int mx = 234567;



vll arr;
void solve(int cs){
    int n;
    LL k;
    cin>>n>>k;
    FOR(i,n){
        LL a,b;cin>>a>>b;
        arr.pb(pll(a,b));
    }

    sort(arr.begin(),arr.end());

    LL curcoin = k;
    LL mypos = 0;
    for(int i=0;i<n;i++){
        pll x = arr[i];
        LL dist = x.first;
        if( mypos+curcoin < dist ){
            mypos += curcoin;
            break;
        }
        else{
            curcoin -= dist-mypos;
            mypos = dist;
            curcoin += x.second;
        }

        if( i==n-1 ){
            mypos += curcoin;
        }

//        deb(i);deb(mypos);deb(curcoin);dnl;
    }


    cout<<mypos<<endl;


}

int main(){

    BOOST;
    #ifdef MujahidPC
        double start = clock();
//        READ;
//        WRITE;
    #endif

    int t;
    t = 1;
//    cin>>t;
    FOR(cs,t)solve(cs+1);


    #ifdef MujahidPC
        double tim = (clock() - start)/CLOCKS_PER_SEC;
        cerr<<"Running Time : "<<tim<<" \n";
    #endif
    return 0;
}
//#include <atcoder/all>
//using namespace atcoder;
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPR(i, n) for(int i=n; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)
#define ALL(v) v.begin(), v.end()
#define bit(n) (1LL<<(n))
#define FIX(d) fixed << setprecision(d)
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const ll LINF = (1LL<<60);

template <typename T>
struct PrimeFact {
  vector<T> spf;
  PrimeFact(T N) { init(N); }
  void init(T N) { // 前処理。spf を求める
    spf.assign(N + 1, 0);
    for (T i = 0; i <= N; i++) spf[i] = i;
    for (T i = 2; i * i <= N; i++) {
      if (spf[i] == i) {
        for (T j = i * i; j <= N; j += i) {
          if (spf[j] == j) spf[j] = i;      
        }
      }
    }
  }
  map<T, T> get(T n) { // nの素因数分解を求める
    map<T, T> mp;
    while (n != 1) {
      mp[spf[n]]++;
      n /= spf[n];
    }
    return mp;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int a,b; cin >> a >> b;

  //PrimeFact pf(b);
  int sub = b-a;
  REPR(i,sub){
    int low = (a/i)*i;
    if(low < a) low += i;
    int high = (b/i)*i;
    if(low<high){
      cout << i << endl;
      return 0;
    }
  }
  
  return 0;
}
