Problem: Problem

You were asked by a company to create a program. The company has $ N $ jobs, and each job is numbered from $ 1 $ to $ N $. There are $ M_i $ prerequisite jobs $ X_ {i, j} $ in job $ i $, and work $ X_ {i, j} $ is performed before job $ X_ {i, j} $. And work $ i $ suffers a great loss.

So ask you to find the number of jobs you lost when you did all the jobs in the order that minimized the number of jobs you lost.

Constraints

The input satisfies the following conditions.

* $ 1 \ le N \ le 10 ^ 5 $
* $ 0 \ le M_i \ le N $
* Sum of $ M_i $ does not exceed $ 10 ^ 5 $
* $ 1 \ le X_ {i, j} \ le min (i + 1, N) $

Input

All inputs are given as integers in the following format:


$ N $
$ M_1 $ $ X_ {1,1} $ $ X_ {1,2} $ ... $ X_ {1, M_1} $
$ M_2 $ $ X_ {2,1} $ $ X_ {2,2} $ ... $ X_ {2, M_2} ​​$
::
$ M_N $ $ X_ {N, 1} $ $ X_ {N, 2} $ ... $ X_ {N, M_N} $


The number of jobs $ N $ is given to the $ 1 $ line.
The following $ N $ line gives information on the prerequisite work. Information on work $ i $ is given on the $ i + 1 $ line, separated by blanks. $ M_i $ represents the number of jobs that are the premise of work $ i $, and $ X_ {i, j} $ is the number of jobs that are the premise of job $ i $.

Output

When all the jobs are done in the order that minimizes the number of jobs incurred, the number of jobs incurred at that time is output in one line.

Examples

Input

2
1 1
0


Output

1


Input

3
3 2 1 2
0
1 2


Output

1


Input

5
1 2
1 3
2 1 2
3 1 3 5
0


Output

1

Solution (in CPP):

Solution:
#include "bits/stdc++.h"

#pragma warning(disable:4996)
using namespace std;
using ld = long double;
struct Edge {
	int src;
	int dst;
	long long int A;
	long long int B;
};
struct aa {
	int now;
	long long int cost;
};
bool operator <(const aa&l, const aa&r) {
	return l.cost>r.cost;
}
long long int ce(long long int a,long long  int b) {
	return (a-1)/b+1;
}
int main() {
	int N;cin>>N;
	vector<int>valids(N,true),need_next(N),need_pre(N);
	vector<int>l_cnts(N);
	for (int i = 0; i < N; ++i) {
		int K;cin>>K;
		vector<int>v;
		for (int k = 0; k < K; ++k) {
			int a;cin>>a;
			a--;
			v.push_back(a);
			if (a == i) {
				valids[i]=false;
			}
			if (a == i - 1) {
				need_pre[i]=true;
			}
			else if (a == i + 1) {
				need_next[i]=true;
			}
		}
		sort(v.begin(),v.end());
		v.erase(unique(v.begin(),v.end()),v.end());
		auto it=lower_bound(v.begin(),v.end(),i);
			
	
		l_cnts[i]=it==v.begin()?30000000:i-*prev(it);
	}
	vector<int>dp(N+1);
	for (int i = 0; i < N; ++i) {

		dp[i + 1] = max(dp[i+1],dp[i]);
		if (!valids[i]) {
		}
		else {
			if (need_next[i]) {
				int k=i+1;
				int sum=1;
				while (true) {
					if (l_cnts[k]<=sum) {
						dp[k+1]=max(dp[k+1],dp[i]+sum);
						break;
					}
					else {
						if (valids[k]) {
							if (need_next[k]) {
								dp[k+1]=max(dp[k+1],dp[i]+sum);
								k++;
								sum++;
								continue;
							}
							else {
								if (l_cnts[k] > sum) {

									dp[k + 1] = max(dp[k + 1],dp[i]+ sum + 1);
								}
								else {
									assert(false);
									dp[k+1]=max(dp[k+1],dp[i]+sum);
								}
								break;
							}
						}
						else {
							dp[k+1]=max(dp[k+1],dp[i]+sum);
							break;
						}
					}
				}
			}
			else {
				dp[i+1]=max(dp[i]+1,dp[i+1]);
			}
		}
	}
	cout<<N-dp[N]<<endl;
	return 0;
}