local n=io.read("n")
local testimony={}
for i=1,n do
    testimony[i]={}
    local a=io.read("n")
    for j=1,a do
        local x,y=io.read("n","n")
        table.insert(testimony[i],{x,y})
    end
end

local function check(bit)
    local checker=true
    for i=1,n do
        if (bit & 1<<i)>0 then
            for k,v in pairs(testimony[i]) do
                local x=v[1]
                local y=v[2]
                if y==1 and (bit & 1<<x)==0 then
                    checker=false
                end
                if y==0 and (bit & 1<<x)>0 then
                    checker=false
                end
            end
        end
    end
    return checker
end

local max=0
for bit=1,1<<n do
    if check(bit) then
        local counter=0
        for i=1,n do
            if (bit & (1<<i))>0 then
                counter=counter+1
            end
        end
        max=math.max(counter,max)
    end
end
print(max)