Type TGrade=Array[1..100,1..100] Of Word;
     TGel=Array[1..100] Of Byte;
     TStr=Array[1..100] Of String[3];
Var N,P:Byte;
    a:TGrade;
    i,j:Byte;
    m:TGel;

Function BTC(b:Byte):Char;
Begin
     BTC:=Chr(Ord('0')+b);
End;

Function CTB(c:Char):Byte;
Begin
     CTB:=Ord(c)-Ord('0');
End;

Procedure Initi(p:Byte;Var a:TGrade);
Var i,j:Byte;
Begin
  j:=0;
  Repeat
       Inc(j);
       For i:=1 To p Do Read(a[j,i]);
  Until j=n;
End;

Function NG(Const a:TGrade;p,r:Byte):Word;
Var i,j:Byte;
    T:TGel;
    nm:Word;
    c:char;
    s:String[101];
Begin
    For i:=1 To p Do t[i]:=a[r,i];
    For i:=1 To p-1 Do
    For j:=i+1 To p Do
    If t[i]>t[j] Then nm:=t[i];
    NG:=nm;
End;

Function NM(Const a:TGrade;p,r:Word):Word;
Var i,j:Word;
    T:TGel;
    nm:Word;
    c:char;
    s:String[101];
Begin
    For i:=1 To p Do t[i]:=a[r,i];
    For i:=1 To p-1 Do
    For j:=i+1 To p Do
    If t[i]<t[j] Then nm:=t[i];
    NM:=nm;
End;


Procedure Koq(n,p:Byte;Const a:TGrade);
Var i,j,k,l:Word;
    c:Byte;
    t:Tgel;
Begin
   j:=0;
   k:=1;
   Repeat
    Inc(j);
    For i:=1 To p Do
      Begin
        If Not NM(a,p,j)=a[j,i] Then
                                    If Not NG(a,p,j)=a[j,i] Then
                                Else
                                     Begin
                                      Repeat
                                       Inc(k);

                                      Until (NG(a,p,k)=a[i,k]) or (k=n);
                                     End;
      End;
    Until j=n;
End;

BEGIN
  Read(N);
  Read(P);
  Initi(P,a);
  Koq(n,p,a)
  ;
END.

If Not NM(a,p,k)=a[k,i] Then
                                If NG(a,p,k)=a[k,i] Then Inc(j);