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

object Main {
  def main(args: Array[String]) {
    val Array(vertical, horizontal) = readLine().split(" ").map(_.toInt)
    var spreadsheet: mutable.Seq[Array[Int]] = mutable.Seq()

    for(i <- 0 until vertical) {
      val inputSpreadsheet = readLine().split(" ").map(_.toInt)
      spreadsheet = spreadsheet :+ (inputSpreadsheet :+ inputSpreadsheet.sum)
    }

    var verticalSum: Array[Int] = Array()
    for(i <- 0 to horizontal) {
      var j = 0
      spreadsheet.foreach(k => j += k(i))
      verticalSum = verticalSum :+ j
    }
    
    spreadsheet = spreadsheet :+ verticalSum

    spreadsheet.foreach(i => println(i.mkString(" ")))
  }
}