#include <iostream>
using namespace std;

int n[101][101];
int main() {
	int r, c;
	cin >> r >> c;
	for (int i = 0; i < r; i++){
		for (int j = 0; j < c; j++){
			cin >> n[i][j];
			n[i][c] += n[i][j];
			n[r][j] += n[i][j];
			n[r][c] += n[i][j];
		}
	}
	for (int i = 0; i <= r; i++){
		for (int j = 0; j < c; j++){
			cout << n[i][j] << " ";
		}
		cout << n[i][c] << endl;
	}
	return 0;
}
