while gets
  n, m = $_.split.map(&:to_i)
  dp = 3.times.map{ [-1] * (m+1) }
  gets
  l = gets.split.map(&:to_i)
  3.times do |i|
    (1..m / l[0]).each do |j|
      dp[i][l[0] * j] = l[i+1] * j
    end
  end
  (n-1).times do
    gets
    l = gets.split.map(&:to_i)
    3.times do |i|
      (m / l[0]).times do |j|
        if dp[i][j] != -1
          ((m - j) / l[0]).downto(1) do |k|
            dp[i][j + l[0] * k] = [dp[i][j + l[0] * k], dp[i][j] + l[i+1] * k].max
          end
        end
      end
    end
  end
  p dp.flatten.max
end