#include <iostream>

using namespace std;

const int MAXN = 100 + 10;

int matrix[MAXN][MAXN];

int main () {
	int m, n;
	while (cin >> m >> n){
		for (int i = 0; i < m; i++){
			for (int j = 0; j < n; j++){
				cin >> matrix[i][j];
			}
		}
		for (int i = 0; i < m; i++){
			int maxnum = matrix[i][0], maxj = 0, rowsum = 0;
			for (int j = 0; j < n; j++){
				if (matrix[i][j] > maxnum){
					maxnum = matrix[i][j];
					maxj = j;
				}
				rowsum += matrix[i][j];
			}
			matrix[i][maxj] = rowsum;
		}
		for (int i= 0; i < m; i++){
			for (int j = 0; j < n; j++){
				cout << matrix[i][j] << " ";
			}
			cout << endl;
		}
	}
	return 0;
}