#参考 #4023546 by kamina_zzz
N,W = gets.split.map &:to_i
D = [[0, 0]]
m = 0
N.times {
  w,v = gets.split.map &:to_i
  next if w+m > W
  D[0,D.size].each {|d|
    D << [d[0]+w, d[1]-v] if d[0]+w+m <= W
  }
  m = 0
  D.sort!.uniq! {|d| m>d[1] ? m=d[1] : m}
  m = D[0][0]
}
p -D[-1][1]