#! ruby -Ks

INF = 100000000000000000

class Mqueue
	def initialize
		@d = Array.new(0)
		@s = 0
		@e = 0
	end
	
	def push(num,ind)
		while @s < @e
			if @d[@e - 1][0] < num
				@d[@e - 1].pop
				@e -= 1
			else
				break
			end
		end
		@d[@e] = [num,ind]
		@e += 1
	end
	
	def del(ind)
		if @s < @e
			if @d[@s][1] == ind
				@s += 1
			end
		end
	end
	
	def top
		return -INF if @s == @e
		return @d[@s][0]
	end
end

n,d = gets.split(" ").map{|s| s.to_i}
x = Array.new(n)
y = Array.new(n)
n.times do |i|
	x[i],y[i] = gets.split(" ").map{|s| s.to_i}
end
a1 = Array.new(1){[0,0]}
a2 = Array.new(1){[0,0]}
n1 = n / 2
k1 = 1
k2 = 1
for i in 0...n1
	k1.times do |j|
		a1.push([a1[j][0] - x[i],a1[j][1] - y[i]])
		a1.push([a1[j][0] + x[i],a1[j][1] + y[i]])
	end
	k1 *= 3
end
for i in n1...n
	k2.times do |j|
		a2.push([a2[j][0] - x[i],a2[j][1] - y[i]])
		a2.push([a2[j][0] + x[i],a2[j][1] + y[i]])
	end
	k2 *= 3
end
a1.sort!
a2.sort!
mae = k2 - 1
ato = k2 - 1
qu = Mqueue.new
res = 0
k1.times do |i|
	while ato >= 0
		if -d <= a2[ato][0] + a1[i][0]
			qu.push(a2[ato][1],ato)
			ato -= 1
		else
			break
		end
	end
	while mae >= 0
		if d < a2[mae][0] + a1[i][0]
			qu.del(mae)
			mae -= 1
		else
			break
		end
	end
	res = [res,qu.top + a1[i][1]].max
end
print(res,"\n")