r, c = gets.split.map(&:to_i)
x = []
y = []
total = []

r.times do
    a = gets.split.map(&:to_i)
    a << a.reduce(:+)
    print a.join(" ")
    puts ""
    x << a
end

for i in 0...c do
    y << x.transpose[i]
    total << y[i].reduce(:+)
end

total << total.reduce(:+)
print total.join(" ")