import collections

N, M = map(int, input().split(" "))


all_sws = []
for i in range(M):
    elms = list(map(int, input().split(" ")))
    k = elms[0]
    sws = elms[1:]
    all_sws += sws

ps = list(map(int, input().split(" ")))

set_sws = set(all_sws)
col_sw = collections.Counter(all_sws)

#print(all_sws)
print(len(set_sws), N)
if N > M:
    shisu = N - M

    out = 2 ** (shisu)
    print(out)

else:
    sval = 0
    for key, val in col_sw.items():
        sval += val
    sval = sval % 2

    s_p = sum(ps)
    if s_p == sval:
        print(1)
    else:
        print(0)
