#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ull unsigned long long 
typedef vector<int> VI;
typedef vector<ll> VLL ;
typedef vector<ull> VULL; 
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef pair<int,int> PII ;
#define PI 3.141592653589793238
#define mod 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
inline void debugMode() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b)
{
    return (a.second < b.second);
}
int main(){
    fast
    debugMode();
    ll n;
    cin>>n;
    vector<PII> v(n);
    vector<PII> vy(n);
    for(ll i=0;i<n;i++){
        int x,y;
        cin>>x>>y;
        v[i]=MP(x,y);
        vy[i]=v[i];
    }
    sort(v.begin(),v.end());
    sort(vy.begin(), vy.end(), sortbysec);
    if(vy[0]==v[0] && vy[n-1]==v[n-1]){
        int ans=max(abs(v[0].F-v[n-2].F),abs(v[1].F-v[n-1].F));
        int ans1=max(abs(vy[0].S-vy[n-2].S),abs(vy[1].S-vy[n-1].S));
        cout<<max(ans1,ans);
    }
    else{
        int ans3=min(abs(v[0].F-v[n-1].F),abs(vy[0].S-vy[n-1].S));
        int ans=max(abs(v[0].F-v[n-2].F),abs(v[1].F-v[n-1].F));
        int ans1=max(abs(vy[0].S-vy[n-2].S),abs(vy[1].S-vy[n-1].S));
        int ans2=max(ans1,ans);
        cout<<max(ans3,ans2);
    }
    return 0;
}

/**
 * @author: adityasonani
 * */
#include <bits/stdc++.h>

// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")

#define     int          long long
#define     ld        	long double
#define     ln          "\n"
#define     fastio      ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define     MOD         (int) 1000000007
#define     rep(i, n)   for (int i = 0; i < (int)n; i++)
#define     all(x)      (x).begin(), (x).end()
#define     debug(x)    cerr << #x << " = " << x << endl;
#define     debugP(x, y)cerr << #x << " = " << x << endl; cerr << #y << " = " << y << endl;
#define     debugV(x)   cerr << "["; for(auto i: x){ cerr << i << ", ";} cerr << "]" << endl;
#define     precise(x)  cout << fixed << setprecision(x)
#define     MAX         (int) 100007 // 10^5
std::vector<int> gv(int n){std::vector<int> v(n);for(auto &x: v){std::cin>>x;}return v;}


using namespace std;


/*
*/

void solve()
{
    int N, K;
    cin >> N >> K;
	vector<pair<int, int>>vp(N);
	for (auto& i : vp)cin >> i.first >> i.second;
	sort(vp.begin(), vp.end());
	for (auto i : vp) {
		if (K >= i.first) {
			K += i.second;
		}
	}
	cout << K << endl;

}

signed main()
{
    fastio;

    auto start = std::chrono::high_resolution_clock::now();

    int t=1;
    // cin>>t;

    while(t--)
        solve();

    auto stop = std::chrono::high_resolution_clock::now();
    auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(stop - start);

    // cerr << "\nTime taken : " << ((long double)duration.count())/((long double) 1e9) <<" s "<< endl;

    return 0;
}
