#include<bits/stdc++.h>
#define RG register
#define R RG int
#define ll long long
#define D double
#define I inline
using namespace std;
int main()
{
	ll b,c;
	scanf("%lld%lld",&b,&c);
	if(b==0)printf("%lld\n",(c>>1)+(c-1>>1)+1);
	else if(b>0)
	{
		printf("%lld\n",(max(c-2>>1,0ll))+(min((b<<1)-1,(c>>1)+(c-1>>1)))+(c-1>>1)+2);
	}
	else printf("%lld\n",(c>>1)+(min((-b<<1)-1,(c-1>>1)+(c-2>>1)))+(c-1>>1)+2);
	return 0;
}	
#include "bits/stdc++.h"
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;

int N;
vector<int> A,B;

int solve(){
    int res = 2e5;
    REP(i,N) res = min(res,A[i]+B[i]);
    REP(i,N){
        REP(j,N){
            if(i == j) continue;
            res = min(res,max(A[i],B[j]));
        }
    }
    return res;
}

int main(){
    cin >> N;
    A.resize(N); B.resize(N);
    REP(i,N) cin >> A[i] >> B[i];
    cout << solve();
    return 0;
}