#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;
using ld = long double;
using ml = boost::multiprecision::cpp_int;

namespace NyaGadget
{

#define fori(i, ...) if(ll i = -1) for(__VA_ARGS__) if(i++, true)
#define each(i, e, v) fori(i, auto& e: v)
#define size(collection) ((ll) (collection).size())

	struct BaseNP
	{	// N進数を表現するクラス
		long long cardinal_;	// 基数
		// シンボルそのものでなく、シンボルに対応するindexを格納していく
		deque<long long> symbol_index_collection_;
		string symbols_[36] =
		{	// 36進数まで対応
			"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
			"A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
			"K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
			"U", "V", "W", "X", "Y", "Z",
		};

		BaseNP(long long cardinal)
		{
			cardinal_ = cardinal;
			symbol_index_collection_.push_back(0);
		}
		void Inc()
		{	// 返り値なしのインクリメント
			bool carry = true;
			long long index = size(symbol_index_collection_) - 1;
			while (0 <= index && carry)
			{
				if (symbol_index_collection_[index] != cardinal_ - 1)
				{
					symbol_index_collection_[index]++;
					carry = false;
				}
				else
				{	// 桁上り
					symbol_index_collection_[index] = 0;
					if (index == 0)
						symbol_index_collection_.push_front(1);
					carry = true;
				}
				index--;
			}
		}
		BaseNP& operator ++()
		{	// 前置インクリメント
			Inc();
			return *this;
		}
		BaseNP operator ++(int)
		{  // 後置インクリメント
			BaseNP np = *this;
			++* this;
			return np;
		}
		/**
		@brief N進数取得関数
		@note
		 d桁のN進数として文字列で取得
		---------------------------------------------------------------------------
		[sample]
		long long main()
		{	// 16進数テスト
			NyaGadgetPositionalNotation pn(16);

			for (long long i = 0; i < 30; i++)
				pn++;

			cout << pn() << endl;		// 30を16進数で表示
			cout << pn(5) << endl;		// 5桁表示

			return 0;
		}
		---------------------------------------------------------------------------
		[output]
		1E
		0001E
		**/
		string operator()(long long d = 0)
		{
			std::string positional_nation;

			each(i, e, symbol_index_collection_)
				positional_nation += symbols_[e];

			if (d == 0 || d == size(positional_nation))
				return positional_nation;

			if (size(positional_nation) < d)
			{	// 表示桁に空きがあるときは0で埋める
				std::string zero(d - size(positional_nation), '0');
				positional_nation = zero + positional_nation;
			}

			return positional_nation;
		}
		/**
		@brief d桁目を取得する演算子
		@note
		 d桁目の数字を文字列で取得する。
		-------------------------------------------------------------------------- -
		[sample]
		long long main()
		{	// 16進数テスト
			NyaGadgetPositionalNotation pn(16);

			for (long long i = 0; i < 30; i++)
				pn++;

			cout << pn.() << endl;		// 30を16進数で表示
			cout << pn[0] << endl;		// １桁目を表示
			cout << pn[1] << endl;		// ２桁目を表示

			return 0;
		}
		-------------------------------------------------------------------------- -
		[output]
		1E
		E
		1
		**/
		char operator[](long long d)
		{	// d桁目の数字を取得する
			long long index = size(symbol_index_collection_) - 1 - d;
			if (index < 0)
				return symbols_[0][0];
			return symbols_[symbol_index_collection_[index]][0];
		}
	};

#undef fori
#undef each
#undef size

}

#define all(c) (c).begin(), (c).end()            // begin to end
#define divc(a, b) ceil((ld) a / (ld) b);        // div ceiling
#define rep(i, b, e) for (ll i = b; i < e; i++)  // repeat
#define repr(i, b, e) for (ll i = b; e < i; i--) // repeat reverse
#define size(c) ((ll) (c).size())                // collection size
#define sum(b, e) accumulate(all(b, e), 0LL)     // accumulate 
/********** const value **********/
#define llong_max 9223372036854775807            // 9 * 10^18
#define ldbl_max 1.79769e+308                    // 1.7 * 10^308
#define mod 1000000007                           // 1e9 + 7
#define pi 3.14159265                            // 3.14 ...
/********** for each macro **********/
#define fori(i, ...) if(ll i = -1) for(__VA_ARGS__) if(i++, true)
#define each(i, e, v) fori(i, auto& e: v)
#define forir(i, ...) if(ll i = size(v)) for(__VA_ARGS__) if(i--, true)
#define eachr(i, e, v) forir(i, auto& e: boost::adaptors::reverse(v))

using namespace NyaGadget;

bool Check(string s, vector<ll>& table)
{

	each(i, e, table)
	{
		if (e == 1 && s[i] != '1')
			return false;
		else if (e == 0 && s[i] != '0')
			return false;
	}

	return true;
}

int main(void)
{
	ll N; cin >> N;

	vector<vector<ll>> table(N, vector<ll>(N, -1));
	rep(i, 0, N)
	{
		ll a;  cin >> a;
		rep(j, 0, a)
		{
			ll x, y; cin >> x >> y;
			table[i][x-1] = y;
		}
	}

	ll ans = 0;
	BaseNP np(2);
	ll maxv = (ll)pow(2, N);
	rep(i, 0, maxv)
	{
		string s = np(N);
		bool ok = true;
		rep(j, 0, size(s))
		{
			if (s[j] == '1')
				ok = Check(s, table[j]);

			if (!ok) break;
		}
		if (ok) ans = max(ans, (ll)count(all(s), '1'));

		++np;
	}

	cout << ans;
	return 0;
}


Measured memory_bytes: 256