import Control.Applicative
import Control.Monad

readInts :: IO [Int]
readInts = map read . words <$> getLine

calc :: Int -> Int -> [[Int]] -> [[Int]]
calc rows cols g = [calc' r | r <- [0..rows]]
  where
    calc' r
      | r < rows = g!!r ++ [sum $ g!!r]
      | otherwise = map (\i -> sum [g!!j!!i | j <- [0..rows-1]]) [0..cols-1] ++ [total]
    total = sum $ map sum g

main :: IO ()
main = do
  [r, c] <- readInts
  xs <- replicateM r readInts
  mapM_ putStrLn $ map (unwords . map show) $ calc r c xs