import scala.collection.mutable
import scala.io.StdIn

/**
  * AOJ
  */
object Main {

  def main(args: Array[String]): Unit = {

      val in = StdIn.readLine().split(" ").map(_.toInt)
      val sheet = readCells(in(0),0,List.empty[List[Int]])

      for(row <- sheet){
        println(row.mkString(" ") + " " + row.sum)
      }
      val columnSummary = getColumnSummary(sheet,List.fill(in(1))(0))
      println(columnSummary.mkString(" ") + " " + columnSummary.sum)
  }

  def readCells(r:Int,i:Int,sheet:Seq[List[Int]]):Seq[List[Int]] = {
    if(r == i){
      sheet
    } else {
      readCells(r,i + 1,sheet :+ StdIn.readLine().split(" ").map(_.toInt).toList)
    }
  }

  def getColumnSummary(sheet:Seq[List[Int]],sum:List[Int]):List[Int] = {
    if(sheet.size == 0){
      sum
    } else {
      getColumnSummary(sheet.tail,(sum,sheet.head).zipped.map(_ + _))
    }
  }
}