import Control.Monad
import Control.Applicative
import Data.Functor
import Data.List

main = do
    [r, c] <- map read . words <$> getLine
    a <- replicateM r $ map read . words <$> getLine
    let ta = a ++ [map sum . transpose $ a]
    forM_ ta (\s -> putStrLn . unwords . map show $ s ++ [sum s])