#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e12);
const ll mod = ll(1e9+7);
const double pi = acos(-1);
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,1,-1};

ll gcd(ll a,ll b){
    if(a < b)swap(a, b);
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll ans = 1;
    rep1(i, n){
        ans *= i;
        ans %= mod;
    }
    return ans;
}

ll power(ll a, ll b){
    ll ans = 1;
    a %= mod;
    while(b) {
        if(b & 1LL) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}

//modの値の確認をすること
int main(){
    ll n,ans = 0;
    cin >> n;
    vector<ll> s(n);
    rep0(i, n){
        ll a,b;
        cin >> a >> b;
        ans -= b;
        s[i] = a + b;
    }
    sort(all(s),greater<>());
    rep0(i, (n + 1) / 2)ans += s[i * 2];
    pf(ans);
    return 0;
}

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

int main(){
  int N,x,y;
  int ans=0;
  cin>>N;
  int A[N];//証言の数
  vector<pair<int,int>>T[N];
   
  //証言を入力  
  for(int i=0;i<N;i++){
    cin>>A[i];
    for(int j=0;j<A[i];j++){
      cin>>x>>y;
      x--;
      T[i].push_back({x,y});
    }
  }
  
  //bit全探索
  for(int i=0;i<(1<<N);i++){
    int cnt=0;//正直者の数
    for(int j=0;j<N;j++){
      if(i & (1<<j)){
        cnt++;
      }
    }
    
    int flag=1;
    for(int j=0;j<N;j++){
      if(i & (1<<j)){     
        //jが正直者として証言が矛盾しないかチェック　矛盾したらflag=0でbreak;
        for(int k=0;k<A[j];k++){
          if(i & 1<<(T[j].at(k).first)){
            if(T[j].at(k).second==1){
              continue;
            }
            else{
              flag=0;
              break;
            }
          }
          else{
            if(T[j].at(k).second==0){
              continue;
            }
            else{
              flag=0;
              break;
            }
          }
        }
      }
    }
    if(flag){
      ans=max(ans,cnt);
    }
  }
  cout<<ans<<endl;
  return 0;
}
