function Main(input) {
const info = input.trim().split('\n');
const cr = info[0].split(' ').map(Number);
row = cr[0];
col = cr[1];
info.shift();

let arryA = [];
for (let i = 0; i <= row; i++){
arryA.push([]);
for (let j = 0; j <= col; j++){
arryA[i].push([]);
}
}

let arryB = [];
for (let i = 0; i < row; i++){
arryB.push(info[i].trim().split(' ').map(Number));
}

for (let i = 0; i < row; i++){
for (let j = 0; j < col; j++){
arryA[i][j] = arryB[i][j];
}
}

for (let i = 0; i < row; i++){
let colsum = 0;
for (let j = 0; j < col; j++){
colsum += arryA[i][j];
}
arryA[i][col] = colsum;
}

for (let i = 0; i <= col; i++){
let rowsum = 0;
for (let j = 0; j < row; j++){
rowsum += arryA[j][i];
}
arryA[row][i] = rowsum;
}

for (let i = 0; i < row + 1; i++){
result = arryA[i].join(' ');
console.log(result);
}


}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
