import Control.Monad
f 
main=do
 [n,m]<-map read.words<$>getLine
 ss<-replicateM m (map read.words<$>getLine)
 pn<-map read.words<$>getLine
 let ns=n`div`2
     aho=[x1:x2:x3:x4:x5:x6:x7:x8:x9:x10:[]|x1<-[1,0],x2<-[1,0],x3<-[1,0],x4<-[1,0],x5<-[1,0],x6<-[1,0],x7<-[1,0],x8<-[1,0],x9<-[1,0],x10<-[1,0]]
     s=zip pn (map init ss)
     ans=foldl (\x y->let p1=[x!!(a-1)|a<-snd y];p2=[|a<-p1]) aho s