import Data.List

main :: IO ()
main = do
  _:m:_ <- words <$> getLine
  ls <- (map words) <$> lines <$> getContents
  let is = map (map (\x -> (read x::Integer))) ls in
    let  ss = (map sum is) :: [Integer] in
      let gs = take (read m::Int) $ reverse $ sort ss in
        putStrLn $ show $ sum gs
