#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_C
r,c = gets.split.map(&:to_i)

table = []
r.times.each do
    table.push gets.split.map(&:to_i)
end

sumrow=[]
(c+1).times do
    sumrow.push 0
end


table.each do |row|
    row.push row.inject(0){|sum,i|sum+i}
    
    for i in 0..c
        sumrow[i]= sumrow[i]+row[i]
    end
end

table.push sumrow

p table