/*
TASK: matrix
LANG: C++
*/
#include <iostream>
#include <string.h>
using namespace std;
int data[1001][1001];
int x = 0;
int y = 0;
int solve();
bool compare(int p1, int p2);
int main()
{
cin >> x >> y;
for (int i=0; i<= x-1; i++)
    for (int j=0; j<= y-1; j++)
        cin >> data[i][j];
cout << x - solve();
//cout << compare(0, 1);
/*
for (int i=0; i<= x-1; i++)
    {
    cout << "\n";
    for (int j=0; j<= y-1; j++)
        cout << data[i][j] << " ";
    }
*/
cin >> x;
return 0;
}

int solve()
{
int res = 0;
for (int i = 0; i<=x-1;i++)
{
 for (int j = i+1; j <=x-1; j++)
 {
  if(compare(i, j)) res++;
 }
}
return res;
}

bool compare(int p1, int p2)
{
 int ret = 0;
 bool th[y];
 bool th0[y];
 for(int a = 0; a <= y; a++)
 {
  th[a] = false;
  th0[a] = false;
 }
 for (int i = 0; i<=y-1; i++)
 {
  for(int j = 0; j <= y-1; j++)
  {
   if((data[p1][i] == data[p2][j]) && !th[j] && !th0[i])
   {
    th[j] = true;
    th0[i] = true;
    ret++;
    j = y;
   }
  }
 }
 if(ret == y) return true;
 else return false;
}
