r, c = STDIN.gets.split(' ').map(&:to_i)
csum = Array.new(c, 0)
r.times do |i|
  ary = STDIN.gets.split(' ').map(&:to_i)
  c.times do |j|
    csum[j] += ary[j]
  end
  ary << ary.reduce{|sum, n| sum + n}
  puts ary.join(' ')
end
csum << csum.reduce{|sum, n| sum + n}
puts csum.join(' ')