def print_table(table)
	r = table.length
	c = table[0].length
	for row_i in 0..r-1
		print "#{table[row_i][0]}"
		for col_i in 1..c-1
			print " #{table[row_i][col_i]}"
		end
		puts "" if row_i != r-1
	end
end

inputs = gets.strip().split(" ").map{|i| i.to_i}
r, c = inputs[0], inputs[1]
table = Array.new(r+1){Array.new(c+1){0}}

for row_i in 0..r-1
	c_sum = 0
	rows = gets.strip().split(" ").map{|i| i.to_i}
	for col_i in 0..c-1
		table[row_i][col_i] = rows[col_i]
		c_sum += rows[col_i]
	end
	table[row_i][c] = c_sum
end
for col_i in 0..c
	for row_i in 0..r-1
		table[r][col_i] += table[row_i][col_i]
	end
end
print_table(table)
