#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1000000007;
const ll N=998244353;
ll power(ll x,ll n){ll res=1;while(n>0){if(n&1) res=res*x%MOD;x=x*x%MOD;n>>=1;}return res;}
ll modinverse(ll a){return power(a, MOD-2);}
void solve()
{
    ll n, k;
    cin>>n>>k;
    vector<vl> pos(n, vl(2, 0));
    forr(i, n)
    {
    	cin>>pos[i][0]>>pos[i][1];
    }
    sort(all(pos));
    ll po=0;
    ll money=k;
    forr(i, n)
    {
    	if(pos[i][0]-po<=money)
    	{
    		money-=(pos[i][0]-po);
    		po=pos[i][0];
    		money+=pos[i][1];
    	}
    	else
    	{
    		po+=money;
    		cout<<po<<endl;
    		return;
    	}
    }
    cout<<po+money<<endl;
}
int main()
{
	#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll test=1;
    //cin>>test;
    while(test--)
    {
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}
#include <bits/stdc++.h>
using namespace std;

#define LL long long
#define pii pair<LL, LL>

int cnt;
LL B, C;

pii a[5];

int main()
{
	scanf("%lld %lld", &B, &C);
	
	a[++ cnt] = pii(B, B + (C - 2) / 2);
	a[++ cnt] = pii(-B, -B + (C - 1) / 2);
	a[++ cnt] = pii(B - C / 2, B);
	a[++ cnt] = pii(-B - (C - 1) / 2, -B);
	
	sort(a + 1, a + cnt + 1);
	
	int i = 1;
	LL ans = 0, r;
	while(i <= cnt)
	{
		int j = i + 1;
		r = a[i].second;
		while(j <= cnt && a[j].first <= r) r = max(r, a[j].second), j ++;
		ans += r - a[i].first + 1;
		i = j;
	}

	printf("%lld\n", ans);
	return 0;
}
