#define F(i,n)for(int i=n;i--;) int n,m,d[200][202][100],a,e,z; int main(){ scanf("%d%d",&n,&m);a=z=2*n; F(k,m)F(i,n)F(j,n)scanf("%d",&e),d[k][i][j]=d[k][n+j][i]=d[k][i-j?0:z][j]=d[k][n-i-j-1?0:z+1][j]=e; F(k,m)F(l,k)F(p,z+2)F(q,z+2)F(x,(e=z,n))F(y,n)a=(e-=d[k][p][x]==d[l][q][y])