#include <stdio.h>
#include <map>
#include <algorithm>
#include <math.h>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;

#define MP(x,y) make_pair(x,y)

const ll INF = 1LL<<60;

struct SegTree{
	ll data[1<<25];
	int s=1;
	void Initialize(pll* d,int len){
		while(s<len)s<<=1;
		for(int i=0;i<len;i++)
			data[s+i] = d[i].second;
		for(int i=len;i<s;i++)
			data[s+i] = -INF;
		for(int i=s-1;i>=1;i--)
			data[i] = max(data[i*2],data[i*2+1]);
	}
	ll _rmq(int b,int e,int l,int r,int i){
		if(r<=b || e<=l)
			return -INF;
		if(b<=l && r<=e)
			return data[i];
		return max(_rmq(b,e,l,(l+r)/2,i*2),_rmq(b,e,(l+r)/2,r,i*2+1));
	}
	ll RMQ(int b,int e){
		if(e<=b)
			return -INF;
		return _rmq(b,e,0,s,1);
	}
};
SegTree seg;

void Calc(pll* ds,ll* vs,ll* ps,int l,int s){
	struct cc{
		pll* dest;
		ll* vals;
		ll* pres;
		int len;
		void _calc(int c,int idx,ll v,ll p){
			if(c == len)
				dest[idx] = MP(v,p);
			else{
				_calc(c+1,idx*3,v-vals[c],p-pres[c]);
				_calc(c+1,idx*3+1,v+vals[c],p+pres[c]);
				_calc(c+1,idx*3+2,v,p);
			}
		}
	};
	cc c = cc{ds,vs,ps,l};
	c._calc(0,0,0,0);
	
	sort(ds,ds+s);
}

pll avp[1<<24],bvp[1<<24];

int power3(int k){
	if(k==0)
		return 0;
	else if(k==1)
		return 3;
	else
		return 3*power3(k-1);
}

int main(){
	int n;
	ll d;
	scanf("%d%lld",&n,&d);
	ll vals[30];
	ll pres[30];
	
	for(int i=0;i<n;i++)
		scanf("%lld%lld",vals+i,pres+i);
	
	int size1 = power3(n-n/2);
	int size2 = power3(n/2);
	
	Calc(avp,vals+n/2,pres+n/2,n-n/2,size1);
	Calc(bvp,vals,pres,n/2,size2);
	
	seg.Initialize(bvp,size2);
	int l=0;
	int r=0;
	ll ans=0;
	for(int i=size1-1;i>=0;i--){
		if(abs(avp[i].first)<=d)
			ans = max(ans,avp[i].second);
		while(l<size2 && bvp[l].first + avp[i].first < -d) l++;
		while(r<size2 && bvp[r].first + avp[i].first <= d) r++;
		ans = max(ans,avp[i].second+seg.RMQ(l,r));
	}
	
	printf("%lld\n",ans);
}