r, c = gets.split.map(&:to_i)
sum_arr = Array.new(c+1, 0)
ARGF.each_line do |line|
  arr = line.split.map(&:to_i)
  arr << arr.inject(:+)
  puts arr.join("\s")
  (c+1).times do |i|
    sum_arr[i] += arr[i]
  end
end

puts sum_arr.join("\s")