#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<vector<pair<int, int>>> V(N);
  for (int i = 0, a; cin >> a; i++)
    for (int j = 0, x, y; j < a && cin >> x >> y; j++) V.at(i).push_back({--x, y});

  int ans = 0;
  for (int bit = 0; bit < 1 << N; bit++) {
    for (int i = 0; i < N; i++) if (bit >> i & 1)
      for (auto v : V.at(i)) if (bit >> v.first & 1 ^ v.second) goto NG;
    ans = max(ans, __builtin_popcount(bit));
    NG:;
  }

  cout << ans << "\n";
}