height,width = gets.split.map(&:to_i)

# 入力

input_line = []
last_line = Array.new(width+1){0}
lines = []

for input_count in 0...height

  input_line = gets.split.map(&:to_i)
  input_line = input_line[0...width]
  input_line << input_line.inject{|sum,n| sum + n }

  for str_count in 0..width
    last_line[str_count] += input_line[str_count]
  end

  lines << input_line
end

lines << last_line

# 出力

for output in lines

  print output.join(" ") + "\n"

end
