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