'use strict'
function main(inp) {
  inp = inp.trim().split('\n')
  const N = Number(inp.shift())
  let say = [...Array(N)].map(() => [])
  let mode = 0
  let count = -1
  inp.forEach(l => {
    l = l.split(' ').map(n => Number(n))
    if (mode) {
      say[count].push([l[0]-1, l[1]])
      mode--
    } else {
      mode = l
      count++
    }
  })

  let ans = 0
  let bit = Math.pow(2, N) - 1
  for (let i = 1; i <= bit; i++) {
    let people = new Array(N).fill(-1)
    let count = (i.toString(2).split('1').length) - 1
    let doubt = false
    for (let j = 1; j < bit; j *= 2) {
      if (i & j) {
        let index = Math.log(j)/Math.log(2)
        say[index].forEach(is => {
          if (Math.pow(2, is[0]) & i) {
            if (people[is[0]] === -1) {
              people[is[0]] = is[1]
            }
            if (people[is[0]] !== is[1]) {
              doubt = true
            }
          } else {
            doubt = true
          }
        })
        if (doubt) break
      }
    }
    if (!doubt) {
      if (ans < count) ans = count
    }
  }
  console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
