r, c = gets.split.map(&:to_i)
sums = [0] * (c + 1)

r.times do
	nums = gets.split.map(&:to_i)
	nums << nums.inject(&:+)
	puts nums.join(' ')
	nums.each_with_index {|n, i| sums[i] += n}
end

puts sums.join(' ')