n, m = gets.split.map(&:to_i)
ary = []
n.times do
  ary << gets.split.map(&:to_i)
end

sum = 0
(0..(n-1)).each do |j|
  (0..m).each do |i|
    if i < m
      print "#{ary[j][i]} "
      sum += ary[j][i]
      i += 1
    else
      puts sum
      ary[j] << sum
      i = 0
      sum = 0
    end
  end
end

ary << []
(0..m).each do |k|
    (0..(n-1)).each do |l|
        sum += ary[l][k]
    end
    ary[n] << sum
    sum = 0
end

puts ary[n].join" "
