r, c = gets.split.map(&:to_i)
sums = Array.new(c + 1, 0)
r.times do
  line = gets.split.map(&:to_i)
  line << line.inject(:+)
  sums = sums.zip(line).map{ |a, b| a + b }
  puts "#{line.join(" ")}"
end
puts sums.join(" ")