#include<iostream>
using namespace std;

int main(){

	int x,y;
	cin >> x >> y;
	int box[110][110];

	for(int i=0;i<x;i++){
		for(int k=0;k<y;k++){
			cin >> box[i][k];
			box[i][y] += box[i][k];
			box[x][k] += box[i][k];
		}
		box[x][y] += box[i][y];
	}

	for(int i=0;i<=x;i++){
		for(int k=0;k<=y;k++){
			if(k != y)	cout << box[i][k] << " ";
			else cout << box[i][k] << endl;
		}
	}

	return 0;
}

