(define(vr v k)(vector-ref v k))
(define(vs v k a)(vector-set! v k a))
(define(mv n a)(make-vector n a))
(define(vvr v y x X)(vector-ref v(+(* y X)x)))
(define(vvs v y x X a)(vector-set! v(+(* y X)x)a))

(define i 0)(define j 0)(define l 0)(define c 0)(define f 0)(define ans 0)
(define n(read))(define m(read))
(define k(mv 20 0))(define s(mv 400 0))(define p(mv 20 0))
(set! i 1)
(while(<= i m)
	(vs k i(read))
	(set! j 1)
	(while(<= j(vr k i))
		(vvs s i j(+(vr k i)1)(read))
		(inc! j)
	)
	(inc! i)
)
(set! i 1)
(while(<= i m)
	(vs p i(read))
	(inc! i)
)
(set! j 0)
(while(< j(ash 1 n))
	(set! c 0)
	(set! i 1)
	(while(<= i m)
		(set! f 0)
		(set! l 1)
		(while(<= l(vr k i))
			(when(>(logand(ash 1(-(vvr s i l(+(vr k i)1))1))j)0)(set! f(logxor f 1)))
			(inc! l)
		)
		(when(=(vr p i)f)(inc! c))
		(inc! i)
	)
	(when(= c m)(inc! ans))
	(inc! j)
)
(print ans)