'use strict';
(function(stdin) {
	var lines  = stdin.toString().split('\n');
	var result = (function(params,data) {
		var table = data.slice(0,params[0]).map(function(v) {
			var tmp = v.split(' ').slice(0,params[1]).map(Number);
			tmp.push(tmp.reduce(function(a,b){ return a + b; }));
			return tmp;
		});

		var line = [];
		for (var i = 0; i < params[1] + 1; i++) {
			var sum = 0;
			for (var j = 0; j < params[0]; j++) {
				sum += table[j][i];
			}
			line.push(sum);
		}
		table.push(line);
		return (table.join('\n').replace(/,/g,' '));


	}(
		lines.shift().split(' ').map(Number)
		,lines
		));

	console.log(result);
}(require('fs').readFileSync('/dev/stdin', 'utf8')));