r,c = gets.split(" ").map(&:to_i)
rs = Array.new(r+1).map{Array.new(c+1,0)}
r.times do |i|
  ti = gets.split(" ").map(&:to_i)
  rs[i][0,c] = ti
  rs[i][c] = ti.inject(:+)
end
rs[r] = rs.transpose.map{|j| j.inject(:+)}
(r + 1).times do |k|
  puts rs[k].join(" ")
end