def II(): return int(eval(input()))

def MI(): return list(map(int, input().split()))

N=II()

shogens=[]

for i in range(N):

  a=II()

  shogens.append([])

  for j in range(a):

    x,y=MI()

    x-=1

    shogens[-1].append((x,y))

def is_honest(i,j):

  return (i>>j)%2==1

def honest_cnt(i):

  ans=0

  for j in range(N):

    ans+=is_honest(i,j)

  return ans

ans=0

for i in range(1<<N):

  ok=True

  for j in range(N):

    if not is_honest(i,j):

      continue

    for (x,y) in shogens[j]:

      if y==0 and is_honest(i,x):

        ok=False

      if y==1 and not is_honest(i,x):

        ok=False  

  if ok:

    ans=max(ans,honest_cnt(i))

print(ans)
def II(): return int(eval(input()))

def MI(): return list(map(int, input().split()))

N=II()

a=[0]*N

x=[[0]*N for i in range(N)]

y=[[0]*N for i in range(N)]

for i in range(N):

  a[i]=II()

  for j in range(a[i]):

    x[i][j],y[i][j]=MI()

    x[i][j]-=1

def check(honest):

  for i in range(N):

    if not honest[i]:

      continue

    for j in range(a[i]):

      if y[i][j]==0 and honest[x[i][j]]:

        return False

      if y[i][j]==1 and not honest[x[i][j]]:

        return False

  return True

def dfs(honest):

  if len(honest)==N:

    if check(honest):

      return sum(honest)

    else:

      return 0

  return max(dfs(honest+[True]),dfs(honest+[False]))

print((dfs([])))
def II():
    return int(eval(input()))


def MI():
    return list(map(int, input().split()))


N = II()
shogens = []
for i in range(N):
    a = II()
    shogens.append([])
    for j in range(a):
        x, y = MI()
        x -= 1
        shogens[-1].append((x, y))


def is_honest(i, j):
    return (i >> j) % 2 == 1


def honest_cnt(i):
    ans = 0
    for j in range(N):
        ans += is_honest(i, j)
    return ans


ans = 0
for i in range(1 << N):
    ok = True
    for j in range(N):
        if not is_honest(i, j):
            continue
        for (x, y) in shogens[j]:
            if y == 0 and is_honest(i, x):
                ok = False
            if y == 1 and not is_honest(i, x):
                ok = False
    if ok:
        ans = max(ans, honest_cnt(i))
print(ans)

def II():
    return int(eval(input()))


def MI():
    return list(map(int, input().split()))


N = II()
a = [0] * N
x = [[0] * N for i in range(N)]
y = [[0] * N for i in range(N)]
for i in range(N):
    a[i] = II()
    for j in range(a[i]):
        x[i][j], y[i][j] = MI()
        x[i][j] -= 1


def check(honest):
    for i in range(N):
        if not honest[i]:
            continue
        for j in range(a[i]):
            if y[i][j] == 0 and honest[x[i][j]]:
                return False
            if y[i][j] == 1 and not honest[x[i][j]]:
                return False
    return True


def dfs(honest):
    if len(honest) == N:
        if check(honest):
            return sum(honest)
        else:
            return 0
    return max(dfs(honest + [True]), dfs(honest + [False]))


print((dfs([])))

-shogens = [] +a = [0] * N +x = [[0] * N for i in range(N)] +y = [[0] * N for i in range(N)] -    a = II() -    shogens.append([]) -    for j in range(a): -        x, y = MI() -        x -= 1 -        shogens[-1].append((x, y)) +    a[i] = II() +    for j in range(a[i]): +        x[i][j], y[i][j] = MI() +        x[i][j] -= 1 -def is_honest(i, j): -    return (i >> j) % 2 == 1 +def check(honest): +    for i in range(N): +        if not honest[i]: +            continue +        for j in range(a[i]): +            if y[i][j] == 0 and honest[x[i][j]]: +                return False +            if y[i][j] == 1 and not honest[x[i][j]]: +                return False +    return True -def honest_cnt(i): -    ans = 0 -    for j in range(N): -        ans += is_honest(i, j) -    return ans +def dfs(honest): +    if len(honest) == N: +        if check(honest): +            return sum(honest) +        else: +            return 0 +    return max(dfs(honest + [True]), dfs(honest + [False])) -ans = 0 -for i in range(1 << N): -    ok = True -    for j in range(N): -        if not is_honest(i, j): -            continue -        for (x, y) in shogens[j]: -            if y == 0 and is_honest(i, x): -                ok = False -            if y == 1 and not is_honest(i, x): -                ok = False -    if ok: -        ans = max(ans, honest_cnt(i)) -print(ans) +print((dfs([])))