#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
string s[1001];
int n,c,x,y,cp,p,ans;
int ch(int x,int y){
  if(s[n-y-1][n-x-1]!=s[y][x])return 0;
  if(s[n-y-1][x]!=s[y][x])return 0;
  if(s[y][n-x-1]!=s[y][x])return 0;
  return 1;
}
int main(){
  cin>>c>>n;
  r(i,n)cin>>s[i];
  r(i,n/2)r(j,n/2)cp+=ch(j,i)*4;
  if(cp==n*n)ans++;
  r(i,c-1){
    cin>>p;
    r(i,p){
      cin>>y>>x;x--;y--;
      cp-=ch(x,y)*4;
      if(s[y][x]=='0')s[y][x]='1';
      else s[y][x]='0';
      cp+=ch(x,y)*4;
    }
    if(cp==n*n)ans++;
  }
  cout<<ans<<endl;
}