'use strict'

const main = arg => {
    var input = arg.trim().split("\n");
    var configInfo = input[0].split(" ").map(str => parseInt(str, 10));
    const rowNum = configInfo[0];
    const columnNum = configInfo[1];
    const datasheet = input.slice(1, 1 + rowNum);
    const result = [];

    datasheet.forEach(data => {
        const nums = data.split(" ").map(str => parseInt(str, 10));
        const sum = nums.reduce((a, b) => a + b);
        nums.push(sum);
        result.push(nums);
    })

    result.push([...Array(columnNum+1)].map(obj => 0));
    for(var i=0;i<columnNum+1;i++){
        for(var j=0;j<rowNum;j++){
            result[rowNum][i] += result[j][i];
        }
    }

    const finalResult = result.map(row => row.join(" ")).join("\n");
    console.log(finalResult);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));
