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
    forM_ a (\s -> putStrLn . unwords . map show $ s ++ [sum s])
    let ta = map sum . transpose $ a
    putStrLn . unwords . map show $ ta ++ [sum ta]