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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (long long i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;

int n,m;
vector<int> v[501];
set<int> st,ss;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

    while(true) {
	cin>>n>>m;
	if(n==0&m==0) break;
	REP(i,501) v[i].clear();
	st.clear();ss.clear();
	REP(i,m) {
		int a,b;
		cin>>a>>b;
		v[a].pb(b);
		v[b].pb(a);
	}
	st.insert(1);
	REP(i,v[1].size()) {
		st.insert(v[1][i]);
	}
	for(auto x:st) {
		REP(i,v[x].size()) {
			ss.insert(v[x][i]);
		}
	}
	for(auto x:st) {
		ss.insert(x);
	}
	cout<<ss.size()-1<<endl;
    }

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    int n, ans = 0;
    cin >> n;
    vector<int> a(n);
    vector<vector<int> > x(n), y(n);
    rep(i, n){
        cin >> a[i];
        rep(j, a[i]){
            int X, Y;
            cin >> X >> Y;
            X--;
            x[i].push_back(X);
            y[i].push_back(Y);
        }
    }
    rep(bit, 1<<n){
        bitset<16> tmp(bit);
        if((int)tmp.count() < ans) continue;
        bool ok = true;
        rep(i, n) {
            // 正直な人
            if(tmp.test(i)){
                rep(j, a[i]) {
                    // x[i][j]は正直者だと正直者が言っているのに実際には正直者ではない
                    if(tmp.test(x[i][j]) && y[i][j] == 0) {
                        ok = false;
                        break;
                    }
                    if(!tmp.test(x[i][j]) && y[i][j] == 1) {
                        ok = false;
                        break;
                    }
                }
            }
        }
        if(ok) chmax(ans, (int)tmp.count());
    }
    cout << ans << endl;
}