Const
maxn = 100;
type
myarr = array [1..maxn, 1..maxn] of longint;
var
a: myarr;
n, i, j, max, ini, c: longint;
begin
readln(n, m);
for i := 1 to n do begin
max := -maxInt;
for j := 1 to m do begin
read(a[i, j]);
if (a[i, j] > max) then begin
max := a[i, j];
ini := j;
end;
end;
c := a[i, i];
a[i, i] := max;
a[i, ini] := c;
end;
for := 1 to n do begin
for j := 1 to m do
write(a[i, j], ' ');
writeln;
end;
end.