import Control.Applicative
import Data.Function
import Control.Monad
import Data.List

f xs = xs ++ [sum xs]

g :: [[Int]] -> [[Int]]
g ss = map f ss ++ [map (sum) (transpose ss)]

main = do
    [r,c] <- map read . words <$> getLine
    ss <- replicateM r $ map read . words <$> getLine
    mapM_ (putStrLn <$> unwords . map show) (g ss)
