#include <iostream>
using namespace std;
int a[100][100];
int main()
{
int n, m, nr=0;
cin >> n >> m;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
cin >> a[i][j];
}
}
for (int i = 0; i < n; i++)
{
int OK = 1;
for (int j = 0; j < m-1; j++)
{
if (a[i][j] != a[i][j + 1])
{
OK = 0;
break;
}
}
if (OK) nr++;
}
cout << nr;
return 0;
}