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

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

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


for i in 0..r-1
 for j in 0..c-1
print arr[i][j]
end
puts " "
end
