#include<iostream>
using namespace std;

int main(){

	int r, c, i, j;
	int ans[101][101] = {0};

	cin >> r >> c;

	for(i=0; i<r; i++){
		for(j=0; j<c; j++){
			cin >> ans[i][j];
			ans[i][c] += ans[i][j];
			ans[r][j] += ans[i][j];
			ans[r][c] += ans[i][j];
		}

	}

	for(i=0; i<=r; i++){
		for(j=0; j<c; j++){
			cout << ans[i][j] << " ";
		}
		cout << ans[i][c]<<endl;
	}

	return 0;

}
