local mmi, mma = math.min, math.max

local n, wtot = io.read("*n", "*n")
local w, v = {}, {}
for i = 1, n do
  w[i], v[i] = io.read("*n", "*n")
end
local buf = w[1] - 1
for i = 1, n do
  w[i] = w[i] - buf
end

local map = {}
for i = 1, n do
  map[i] = {}
  local lim = wtot - buf * i
  lim = mmi(lim, 500)
  for j = 1, lim do
    map[i][j] = 0
  end
end

for i_n = 1, n do
  local iw, iv = w[i_n], v[i_n]
  for i = i_n - 1, 1, -1 do
    for j = 1, #map[i] do
      if 0 < map[i][j] then
        if j + iw <= #map[i + 1] then
          map[i + 1][j + iw] = mma(map[i + 1][j + iw], map[i][j] + iv)
        end
      end
    end
  end
  if iw <= #map[1] then
    map[1][iw] = mma(map[1][iw], iv)
  end
end

local ret = 0
for i = 1, n do
  for j = 1, #map[i] do
    ret = mma(ret, map[i][j])
  end
end
print(ret)
