#include <bits/stdc++.h>

using namespace std;

int C, N, Len, CurSum, Total;
int MapData[10000][10000];

int judge(int row, int col) {
	
	if (MapData[row][col] != MapData[row][N-1-col]) {
		return 0;
	}
	if (MapData[row][col] != MapData[N-1-row][col]) {
		return 0;
	}
	if (MapData[row][col] != MapData[N-1-row][N-1-col]) {
		return 0;
	}
	return 1;
}

int main() {
	int d, r, c;
	string str;

	cin >> C >> N;
	for (int i = 0; i < N; ++i) {
		cin >> str;
		for (int j = 0; j < N; ++j) {
			MapData[i][j] = str[j] - '0';
		}
	}
	Len = N / 2;
	CurSum = 0;
	for (int i = 0; i < Len; ++i) {
		for (int j = 0; j < Len; ++j) {
			CurSum += judge(i, j) * 4;
		}
	}
	Total = 0;
	if (CurSum == N*N) {
		++Total;
	}
	for (int i = 1; i < C; ++i) {
		cin >> d;
		for (int m = 0; m < d; ++m) {
			cin >> r >> c;
			--r;
			--c;
			CurSum -= judge(r, c) * 4;
			MapData[r][c] = (MapData[r][c] == 1 ? 0 : 1);
			CurSum += judge(r, c) * 4;
		}
		if (CurSum == N*N) {
			++Total;
		}
	}
	cout << Total << endl;

	return 0;
}

