#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("date.in");
ofstream fout("date.out");
int a[20][20],i,j,aux,Max,n,m;
int main()
{
fin>>n>>m;
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
fin>>a[i][j];
for(i=1;i<=n;i++)
{
Max=a[i][j];
for(j=1;j<=n;j++)
if(a[i][j]>Max)
Max=a[i][j];
aux=a[i][j];
a[i][j]=a[i][1];
a[i][1]=aux;
}
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
fout<<a[i][j]<<" ";
fout<<"\n";
}
return 0;
}