local mmi, mma = math.min, math.max
local n, wtot = io.read("*n", "*n")
local w, v = {}, {}
w[1], v[1] = io.read("*n", "*n")
local woffset = w[1] - 1
w[1] = 1
for i = 2, n do
  local a, b = io.read("*n", "*n")
  w[i], v[i] = a - woffset, b
end
local dp = {}
for i = 1, n + 1 do
  dp[i] = {}
  for j = 1, 4 * n do
    dp[i][j] = 0
  end
end
for i = 1, n do
  for j = i, 1, -1 do
    for k = 4 * (i - 1), 1, -1 do
      dp[j + 1][k + w[i]] = mma(dp[j + 1][k + w[i]], dp[j][k] + v[i])
    end
    dp[j + 1][w[i]] = mma(dp[j + 1][w[i]], v[i])
  end
end
local ret = 0
for i = 2, n + 1 do
  local offset = woffset * (i - 1)
  for j = 1, (i - 1) * 4 do
    if offset + j <= wtot then
      ret = mma(ret, dp[i][j])
    end
  end
end
print(ret)
