c, r = gets.split.map(&:to_i)
a = Array.new(c+1).map{ Array.new(r+1, 0) }
for i in 0..c-1 do
	a[i] = gets.split.map(&:to_i)
	a[i][r] = 0
end
for i in 0..c-1 do
	for j in 0..r-1 do
		a[i][r] += a[i][j]
	end
end
for i in 0..r do
	for j in 0..c-1 do
		a[c][i] += a[j][i]
	end
end
for i in 0..c do
	puts a[i].join(" ")
end