N,M=input().strip().split()
l1=[]
while True:
    try:
        l1.append(list(map(int,input().split())))
    except:
        break;
l2=l1[-1]
del l1[-1]
n=0
tate=0
yoko=1
count1=0
count2=0
count3=0
while True:
    while True:        
        sw=str(bin(n))
        del sw[0]
        a=l1[tate][yoko]
        if int(sw[a])==1:
            count1=count1+1
        yoko=yoko+1
        if yoko==l1[tate][0]:
            yoko=1
            if count1%2==l2[tate]:
                count2=count2+1
            break
    tate=tate+1
    if tate==M:
        if count2==N:
            count3=1
        n=n=1
        break
        