#include <bits/stdc++.h>
#define MAX 100
using namespace std;

int main() {
    int n, m, i, j, k, max, sum;
    int data[MAX][MAX];
    while (cin >> m >> n) {
        for (i = 0; i < m; i++)
            for (j = 0; j < n; j++)
                cin >> data[i][j];

        for (i = 0; i < m; i++) {
            k = -1, max = -1, sum = 0;
            for (j = 0; j < n; j++) {
                if (data[i][j] > max) {
                    max = data[i][j];
                    k = j;
                }
                sum += data[i][j];
            }
            data[i][k] = sum;
        }

        for (i = 0; i < m; i++) {
            for (j = 0; j < n; j++)
                cout << data[i][j] << " ";
            cout << endl;
        }
    }
}