Var
  a:array [1..20,1..20] of word;
  n,p:longint;
Procedure Show;
Var i,j:byte;
Begin
 For i:=1 to n do Begin
                   For j:=1 to p do write(a[i,j],' ');
                   writeln;
                  End;
End;
Procedure Init;
 Var i,j:byte;
     m:word;
Begin
 For i:=1 To n Do
 For j:=1 To p Do Begin
                   read(m);
                   a[i,j]:=m;
                  End;
End;
Procedure Prosta(i:byte);
Var j,m:byte;
    b,c:word;
Begin
 j:=1;
 For m:=1 to n do Begin
                   repeat
                    if (a[i,j])>(a[i,j+1]) then Begin
                                             b:=a[i,j];
                                             c:=j;
                                            End
                                       else Begin
                                             b:=a[i,j+1];
                                             c:=j+1;
                                            End;
                     inc(j);
                    until Not j<p;
                    a[i,c]:=0;
                    if (m<n) and (i<=n) then prosta(i+1);
                   end;
End;
Begin
 Readln(n,p);
 Init;
 prosta(1);
 show;
End.