let read f = stdin.ReadLine() |> f
let reads f = stdin.ReadLine().Split() |> Array.map f

let n = read int

let table = Array2D.create n n 0
for i = 0 to n-1 do
    let a = read int
    for j = 0 to a-1 do
        let [|x;y|] = reads int
        table.[i, x-1] <- table.[i, x-1] + if y = 1 then 1 else -1

let mutable acc = 0
for i = 0 to n-1 do
    for j = n-1 downto 0 do
        if table.[i, j] <> 0 && table.[i, j] = table.[j, i] then
            acc <- acc + 1
acc <- acc - if n = 2 then 1 else 0
printfn "%d" acc