#include<iostream>

using namespace std;

int main() {
    int m, n;
    cin >> m >> n;
    int** a = new int* [m];
    for (int i = 0; i < m; i++) {
        a[i] = new int[n];
        for (int j = 0; j < n; j++)cin >> a[i][j];
        int max = 0, sum = 0;
        for (int j = 0; j < n; j++) {
            if (a[i][j] > a[i][max])max = j;
            sum += a[i][j];
        }
        a[i][max] = sum;
    }
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < n; j++)cout << a[i][j] << " ";
        cout << endl;
    }
    return 0;
}