process.stdin.setEncoding('ascii');
process.stdin.on('data', function (chunk) {

	var line, rc, r, c, sum, i;

	line = chunk.split(/\r?\n/).map(function (line) {
		if (line.length === 0) return [];
		return line.split(' ').map(Number);
	});

	rc = line.shift();
	r = rc[0];
	c = rc[1];
	line.length = r;

	sum = [];
	for (i = 0; i < c; i++) sum[i] = 0;

	line.forEach(function (line) {
		line.forEach(function addToSum(elem, i) { sum[i] += elem; });
	});
	line.push(sum);
	line.forEach(function (line) {
		line.push(line.reduce(function (a, b) { return a + b; }, 0));
	});

	function join(ary) { return ary.join(' '); }
	console.log(line.map(join).join('\n'));
	
});