n, m = gets.split.map(&:to_i)
ab = n.times.map{gets.split.map(&:to_i)}
moneys = []
ab.permutation(n).each do |p|
  day = 0
  money = 0
  p.each do |a, b|
    next if day + a > m
    money += b
    day += 1
  end
  moneys.push money
end
p moneys.max
