import java.util.Scanner

fun main(args:Array<String>){

    val cin = Scanner(System.`in`)
    val r = cin.nextInt()
    val c = cin.nextInt()
    var table = Array(r+1,{ Array(c+1,{0}) })

    for(i in 0..r-1){
	    for(j in 0..c-1){
	        table[i][j] = cin.nextInt()
	        table[i][c] += table[i][j]
	        table[r][j] += table[i][j]
	        table[r][c] += table[i][j]
	    }
    }

    for(i in 0..r){
	    for(j in 0..c){
	        if(j > 0) print(" ")
	        print(table[i][j])
	    }
	    println()
    }
}
