def abc128c_switches():
    import itertools
    n, m = map(int, input().split())
    s = []
    for _ in range(m):
        v = list(map(int, input().split()))
        v = v[1:]
        s.append(v)
    p = list(map(int, input().split()))
    pattern = itertools.product([0,1], repeat=n)
    result = 0
    for pat in pattern:
        cnt = 0
        for i in range(m):
            total = 0
            for j in s[i]:
                if pat[j-1] == 1:
                    total += 1
            if total %2==p[i]:
                cnt +=1
        if cnt == m:
            result += 1
    print(result)

abc128c_switches() def abc128c_switches():
    import itertools
    n, m = map(int, input().split())
    s = []
    for _ in range(m):
        v = list(map(int, input().split()))
        v = v[1:]
        s.append(v)
    p = list(map(int, input().split()))
    pattern = itertools.product([0,1], repeat=n)
    result = 0
    for pat in pattern:
        cnt = 0
        for i in range(m):
            total = 0
            for j in s[i]:
                if pat[j-1] == 1:
                    total += 1
            if total %2==p[i]:
                cnt +=1
        if cnt == m:
            result += 1
    print(result) abc128c_switches import itertools itertools n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m s = [] s [] for _ in range(m):
        v = list(map(int, input().split()))
        v = v[1:]
        s.append(v)
     _ range(m) range m v = list(map(int, input().split())) v list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split v = v[1:] v v[1:] v 1: 1 s.append(v) s.append s append v p = list(map(int, input().split())) p list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split pattern = itertools.product([0,1], repeat=n) pattern itertools.product([0,1], repeat=n) itertools.product itertools product [0,1] 0 1 repeat=n repeat n result = 0 result 0 for pat in pattern:
        cnt = 0
        for i in range(m):
            total = 0
            for j in s[i]:
                if pat[j-1] == 1:
                    total += 1
            if total %2==p[i]:
                cnt +=1
        if cnt == m:
            result += 1
     pat pattern cnt = 0 cnt 0 for i in range(m):
            total = 0
            for j in s[i]:
                if pat[j-1] == 1:
                    total += 1
            if total %2==p[i]:
                cnt +=1
         i range(m) range m total = 0 total 0 for j in s[i]:
                if pat[j-1] == 1:
                    total += 1
             j s[i] s i if pat[j-1] == 1:
                    total += 1
             pat[j-1] == 1 pat[j-1] pat j-1 j 1 1 total += 1 total 1 if total %2==p[i]:
                cnt +=1
         total %2==p[i] total %2 total 2 p[i] p i cnt +=1 cnt 1 if cnt == m:
            result += 1
     cnt == m cnt m result += 1 result 1 print(result) print result abc128c_switches() abc128c_switches def abc128c_switches():
    import itertools
    n, m = map(int, input().split())
    s = []
    for _ in range(m):
        v = list(map(int, input().split()))
        v = v[1:]
        s.append(v)
    p = list(map(int, input().split()))
    pattern = itertools.product([0,1], repeat=n)
    result = 0
    for pat in pattern:
        cnt = 0
        for i in range(m):
            total = 0
            for j in s[i]:
                if pat[j-1] == 1:
                    total += 1
            if total %2==p[i]:
                cnt +=1
        if cnt == m:
            result += 1
    print(result) def abc128c_switches():
    import itertools
    n, m = map(int, input().split())
    s = []
    for _ in range(m):
        v = list(map(int, input().split()))
        v = v[1:]
        s.append(v)
    p = list(map(int, input().split()))
    pattern = itertools.product([0,1], repeat=n)
    result = 0
    for pat in pattern:
        cnt = 0
        for i in range(m):
            total = 0
            for j in s[i]:
                if pat[j-1] == 1:
                    total += 1
            if total %2==p[i]:
                cnt +=1
        if cnt == m:
            result += 1
    print(result) abc128c_switches
def abc128c_switches():
    import itertools
    n, m = map(int, input().split())
    s = []
    for _ in range(m):
        v = list(map(int, input().split()))
        v = v[1:]
        s.append(v)
    p = list(map(int, input().split()))
    pattern = itertools.product([0,1], repeat=n)
    result = 0
    for pat in pattern:
        cnt = 0
        for i in range(m):
            total = 0
            for j in s[i]:
                if pat[j-1] == 1:
                    total += 1
            if total %2==p[i]:
                cnt +=1
        if cnt == m:
            result += 1
    print(result)

abc128c_switches()