r, c = gets.split.map(&:to_i)
arr = Array.new(r+1).map{ Array.new(c+1, 0) }

for i in 0..r-1 do
    arr[i] = gets.split.map(&:to_i)
    arr[i][c] = 0
end

for i in 0..r-1 do
    for j in 0..c-1  do
        arr[i][c] += arr[i][j]
end
end

for i in 0..c do
    for j in 0..r-1 do
        arr[r][i] += arr[j][i] 
    end
end

puts arr.join(" ")

