import Control.Monad
import Data.List

main = do
  [n,m] <- fmap (map read . words) getLine
  mat <- replicateM n $ fmap (map read . words) getLine :: IO [[Int]]
  let newMat = solve3 mat

  putStr . output $ newMat

solve3 mat = newMat ++ [newLine]
  where
    newMat = map sumAdd mat
    newLine = map sum $ transpose newMat
    -- newLineSum = sum newLine

sumAdd list = list ++ [s]
  where
    s = sum list

output mat = unlines . map unwords . map (map show) $ mat

