r, c = gets.split.map(&:to_i)

ary = []

r.times{
    line = gets.split.map(&:to_i)
    line.push(line.inject(:+))
    ary.push(line)
}

 c += 1

sum_line = []
c.times{|i|
    sum = 0
    for j in 0..(r-1) do
        sum += ary[j][i]
    end
    sum_line.push(sum)
}

ary.push(sum_line)

(r+1).times{|i|
    puts ary[i].join(" ")
}
