function main(input){
    let lines = input.split("\n");
    let args = lines[0].split(" ").map(item=>parseInt(item));
    let height = args[0];
    let width = args[1];
    let rows = lines.slice(1)
    let colSum = new Array(width+1).fill(0);
    let put = "";
    for(let i=0;i<height;i++){
        let sum =0;
        let row = rows[i].split(" ");
        for(let j=0;j<width;j++){
            sum+= parseInt(row[j]);
            colSum[j]+=parseInt(row[j]);
        }
        colSum[width]+=sum;
        put= put + rows[i]+" "+sum+"\n";
    }
    put = put+colSum.join(" ");
    console.log(put);
}



main(require("fs").readFileSync("/dev/stdin","utf-8"));
