r,c = gets.split.map { |e|e.to_i}

table = []
r.times {
  data  = gets.split.map { |e| e.to_i }
  data << data.inject { |sum, i| sum += i }
  table << data
}
table << []
for i in 0..r-1
  for j in 0..c
    if table[r][j].nil? 
      table[r][j] = table[i][j]
    else
      table[r][j] += table[i][j]
    end
  end
end

for tb in table
  puts tb.join(" ")
end