#include <iostream>
#include <algorithm>
#include <cmath>
#define maxn 110
using namespace std;
int a[maxn][maxn];
int main() {
   int n,m;
   while(cin>>m>>n)
   {
        for(int i=0;i<m;i++)
        {
            int ans = 0;
            int pos = 0,maxx = -99;
            for(int j=0;j<n;j++)
            {
                cin>>a[i][j];
                ans += a[i][j];
                if(maxx < a[i][j])
                {
                    maxx = a[i][j];
                    pos = j;
        //            cout<<"pos = "<<pos<<endl;
                }
            }
            a[i][pos] = ans;
        }
        for(int i=0;i<m;i++){
            for(int j=0;j<n;j++){
                cout<<a[i][j]<<" ";
            }cout<<endl;

        }
        
   }

}
// 64 位输出请用 printf("%lld")