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

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

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

puts arr.join("\n")

