r, c = gets.split.map(&:to_i)

lines = []

r.times do
  line = gets.split.map(&:to_i)
  line.push(line.inject(:+))
  lines.push(line)
end

sum = Array.new(c + 1, 0)
lines.each do |line|
  puts line.join("\s")
  sum = sum.zip(line).map{|a, b| a + b }
end
puts sum.join("\s")