$debug=0
def aux(rc)
  rc.each{|r|
    r.push r.sum
  }
  cl=rc[0].length
  rl=rc.length

  cs=[]
  cl.times{|j|
    puts "j: #{j}" if $debug&2==2
    s=0
    rl.times{|i|
      s+=rc[i][j]
    }
    puts "s: #{s}" if $debug&2==2
    cs << s
    puts "cs: #{cs.to_s}" if $debug&2==2
  }
  rc << cs

end

def main
  rc=[]
  if $debug&1==1
    #fh=File.new("ITP1_7_C1.txt", "r")
    fh=File.new("ITP1_7_C2.txt", "r")
  else
    fh=STDIN
  end
  r,c=fh.gets.split.map(&:to_i)
  r.times {
    rc << fh.gets.chomp.split.map(&:to_i)
  }

  rc1=aux(rc)

  s = rc1.map{|r|
    r.map(&:to_s).join(" ")
  }
  s.each {|ln|
    puts ln
  }
end

if $0 == __FILE__ then
  main
end
