import Control.Monad
import Data.List

addCsum :: [Int] -> [Int]
addCsum column = column ++ [sum column]
addRSum :: [[Int]] -> [[Int]]
addRSum rows = rows ++ [map sum (transpose rows)]

addSum :: [[Int]] -> [[Int]]
addSum table = addRSum (map addCsum table)

main = do
  [r, c] <- fmap (map read . words) getLine
  tbl <- replicateM r $ fmap (map read . words) getLine
  mapM_ (putStrLn . unwords . map show) $ addSum tbl