/*
TASK:matrix
LANG:C++
*/
#include<iostream.h>
int N;
int M;
int arr[1001][1001];
long int S[1001];
int podobni(int p, int q);

int main ()
{
	cin>>N>>M;
	int max=0;

	for (int i=1; i<=N; i++)
	{
		for (int t=1; t<=M; t++)
		{	cin>>arr[i][t];
			S[i]=S[i]+arr[i][t];
		}
		if (i>1)
		{
			int pom=0;
			for (int j=1; j<i; j++)
				if (S[i]==S[j]) {pom=pom+podobni(i, j);  }
		
				if (pom==0) max++;
		
		}
	}

	cout<<max<<endl;
	return 0;
}

int podobni(int p, int q)
{

	int m1[1001];
	int m2[1001];

	for (int j=1; j<=M; j++)
		m1[arr[p][j]]++;

	for (int d=1; d<=M; d++)
		m2[arr[q][d]]++;

	for(int t=1; t<=M; t++)
		if (m1[arr[p][t]]!=m2[arr[p][t]]) return 0;

	return 1;
}































