{
TASK:matrix
LANG:PASCAL
}
{$R-,S-}

const
  Max = 3000;

type
  List = array[1..Max] of word;
  Matrix = array[1..Max] of List;

var
  arr: matrix;
  used:List;
  I,J,N,M,Br: Integer;

function Compare(X,Y:List):boolean;
 var i,j:integer;
  begin
   for i:=1 to M do
    if x[i]<>y[i] then
     begin
      Compare:=false;
      exit;
     end;
   Compare:=true;
  end;


procedure QSort(var A: List; Lo, Hi: Integer);

procedure Sort(l, r: Integer);
var
  i, j, x, y: word;
begin
  i := l; j := r; x := a[(l+r) DIV 2];
  repeat
    while a[i] < x do i := i + 1;
    while x < a[j] do j := j - 1;
    if i <= j then
    begin
      y := a[i]; a[i] := a[j]; a[j] := y;
      i := i + 1; j := j - 1;
    end;
  until i > j;
  if l < j then Sort(l, j);
  if i < r then Sort(i, r);
end;

begin
  Sort(Lo,Hi);
end;

begin
 readln(N,M);
 br:=N;

 for i:=1 to N do
  begin
   for j:=1 to M do
    read(arr[i,j]);
   readln;
  end;


 writeln;
 for i:=1 to N do
  qsort(arr[i],1,M);

 for i:=1 to N-1 do
  for j:=i+1 to N do
   if compare(arr[i],arr[j]) then
    used[j]:=1;

 for i:=1 to N do
  if used[i]>0 then
   dec(br);

{  for i:=1 to N do
  begin
   for j:=1 to M do
    write(arr[i,j],' ');
   writeln;
  end;}
  writeln(br);

// readln;
end.
