import Control.Monad
import Data.List

main = do
  [r, c] <- return . map (\x -> read x :: Int) . words =<< getLine
  a <- replicateM r $ getLine >>= return . map (\x -> read x :: Int) . words 
  mapM_ (\x -> do
    putStr $ unwords . map show $ x
    putChar ' '
    putStrLn $ show $ sum x ) a
  let csum = map sum $ transpose a
  putStr $ unwords . map show $ csum
  putChar ' '
  putStrLn $ show $ sum csum