MODE = "stdio"
require 'matrix'
line = Array.new

if(defined? MODE)
  line = STDIN.read.split("\n")
else
  tmp = "\
  4 5
  1 1 3 4 5
  2 2 2 4 5
  3 3 0 1 1
  2 3 4 4 6
  ".split("\n")
  tmp.each{|s|
    line << s.strip
  }
end
r,c=line[0].split(" ").map(&:to_i)

arr = []
(0...r).each do |r|
  tmp = line[r+1].split(" ").map(&:to_i)
  sum = tmp.inject(&:+)
  arr[r] = (tmp << sum)
end

arr = arr.transpose

(0..c).each do |c|
  sum = arr[c].inject(&:+)
  arr[c] << sum
end

arr.transpose.each do |s|
  puts s.join(" ")
end