N = int(eval(input()))

ls = []

for i in range(N):

  a = int(eval(input()))

  for _ in range(a):

    x,y = list(map(int, input().split()))

    ls.append((i,x-1,y==1))

max = 0

for i in range(2**N):

  c = 0

  hon = set()

  unhon = set()

  

  for x in range(N):

    if (i>>x)&1 == 1:

      c += 1

      

  for x,y,z in ls:

    if (i>>x)&1 == 1:

      if z:

        hon.add(y)

      else:

        unhon.add(y)

        

  if len(hon & unhon) == 0:

    flag = True

    for n in range(N):

      if (i>>n)&1 == 1:

        if n in unhon:

          flag = False

          break

      else:

        if n in hon:

          flag = False

          break

    if flag and c >= max:

      max = c

      

print(max)
N = int(eval(input()))



h = []



for i in range(N):

  m = int(eval(input()))

  g = []

  for j in range(m):

    a, b = list(map(int, input().split()))

    g.append((a-1, b))

  h.append(g)

  

def judge(a, b):

  for i in range(N):

    if (b >> i) & 1:

      for j in a[i]:

        if ((b >> j[0]) & 1) != j[1]:

          return False

  return True

  

x = 0b0

ans = -1

for i in range(2**N):

  if judge(h, x):

    tmp = 0

    for i in range(N):

      if (x >> i) & 1:

        tmp += 1

    if tmp > ans:

      ans = tmp

  x += 1



print(ans)
N = int(eval(input()))
ls = []
for i in range(N):
    a = int(eval(input()))
    for _ in range(a):
        x, y = list(map(int, input().split()))
        ls.append((i, x - 1, y == 1))
max = 0
for i in range(2**N):
    c = 0
    hon = set()
    unhon = set()
    for x in range(N):
        if (i >> x) & 1 == 1:
            c += 1
    for x, y, z in ls:
        if (i >> x) & 1 == 1:
            if z:
                hon.add(y)
            else:
                unhon.add(y)
    if len(hon & unhon) == 0:
        flag = True
        for n in range(N):
            if (i >> n) & 1 == 1:
                if n in unhon:
                    flag = False
                    break
            else:
                if n in hon:
                    flag = False
                    break
        if flag and c >= max:
            max = c
print(max)

N = int(eval(input()))
h = []
for i in range(N):
    m = int(eval(input()))
    g = []
    for j in range(m):
        a, b = list(map(int, input().split()))
        g.append((a - 1, b))
    h.append(g)


def judge(a, b):
    for i in range(N):
        if (b >> i) & 1:
            for j in a[i]:
                if ((b >> j[0]) & 1) != j[1]:
                    return False
    return True


x = 0b0
ans = -1
for i in range(2**N):
    if judge(h, x):
        tmp = 0
        for i in range(N):
            if (x >> i) & 1:
                tmp += 1
        if tmp > ans:
            ans = tmp
    x += 1
print(ans)

-ls = [] +h = [] -    a = int(eval(input())) -    for _ in range(a): -        x, y = list(map(int, input().split())) -        ls.append((i, x - 1, y == 1)) -max = 0 +    m = int(eval(input())) +    g = [] +    for j in range(m): +        a, b = list(map(int, input().split())) +        g.append((a - 1, b)) +    h.append(g) + + +def judge(a, b): +    for i in range(N): +        if (b >> i) & 1: +            for j in a[i]: +                if ((b >> j[0]) & 1) != j[1]: +                    return False +    return True + + +x = 0b0 +ans = -1 -    c = 0 -    hon = set() -    unhon = set() -    for x in range(N): -        if (i >> x) & 1 == 1: -            c += 1 -    for x, y, z in ls: -        if (i >> x) & 1 == 1: -            if z: -                hon.add(y) -            else: -                unhon.add(y) -    if len(hon & unhon) == 0: -        flag = True -        for n in range(N): -            if (i >> n) & 1 == 1: -                if n in unhon: -                    flag = False -                    break -            else: -                if n in hon: -                    flag = False -                    break -        if flag and c >= max: -            max = c -print(max) +    if judge(h, x): +        tmp = 0 +        for i in range(N): +            if (x >> i) & 1: +                tmp += 1 +        if tmp > ans: +            ans = tmp +    x += 1 +print(ans)