#include<stdio.h>

const int M = 1000;
const int N = 1000;

int a[M][N];

int main() {
    int m, n;
    while(scanf("%d%d", &m, &n) != EOF) {
        for(int i = 0; i < m; i++)
            for(int j = 0; j < n; j++)
                scanf("%d", &a[i][j]);
        
        for(int i = 0; i < m; i++) {
            int max = 0, sum = 0;
            for(int j = 0; j < n; j++) {
                sum += a[i][j];
                if(a[i][j] > a[i][max]) max = j;
            }
            a[i][max] = sum;
        }

        for(int i = 0; i < m; i++)
            for(int j = 0; j < n; j++)
                if(j == n - 1) printf("%d\n", a[i][j]);
                else printf("%d ", a[i][j]);
    }
    return 0;
}