import Data.Functor( (<$>))
import Control.Monad( replicateM)
import Data.List( transpose)

main = do
    let
	readLine = (read <$>) . words <$> getLine

    [r,c] <- readLine
    rows <- replicateM r readLine
    let
	addSum list = list++[sum list]

	answer = transpose $ addSum <$> (transpose $ addSum <$> rows)

	printList list = do
		putStr . unwords $ show <$> list
		putStrLn ""

    printList `mapM_` answer

