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>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 100005



struct GROUP{
	vector<int> nodes;
};

GROUP group[NUM]; //強連結成分のグループ
int N;
vector<int> G[NUM];
vector<int> reverse_G[NUM];
stack<int> S;
map<pair<int,int>,bool> MAP;

bool check[NUM],SELF[NUM];
int table[NUM],work[NUM];
double sleep[NUM];

int group_index;

void dfs(int node_id){
	check[node_id] = true;

	for(int i = 0; i < G[node_id].size(); i++){
		if(!check[G[node_id][i]])dfs(G[node_id][i]);
	}
	S.push(node_id);
}

void reverse_dfs(int node_id){
	check[node_id] = true;

	table[node_id] = group_index;
	group[group_index].nodes.push_back(node_id); //group[group_index]にノードを突っ込む

	for(int i = 0; i < reverse_G[node_id].size(); i++){
		if(!check[reverse_G[node_id][i]])reverse_dfs(reverse_G[node_id][i]);
	}
}


int main(){

	scanf("%d",&N);

	int num,pre_node;

	for(int i = 0; i < N; i++){

		SELF[i] = false;

		scanf("%d",&num);

		for(int k = 0; k < num; k++){
			scanf("%d",&pre_node);
			pre_node--;

			if(pre_node == i){

				SELF[i] = true;
			}

			auto at = MAP.find(make_pair(pre_node,i));
			if(at != MAP.end())continue;

			MAP[make_pair(pre_node,i)] = true;

			G[pre_node].push_back(i);
			reverse_G[i].push_back(pre_node);
		}
	}

	for(int i = 0; i < N; i++)check[i] = false;

	for(int i = 0; i < N;i++){
		if(!check[i])dfs(i);
	}

	for(int i = 0; i < N;i++)check[i] = false;

	group_index = -1;

	while(!S.empty()){
		if(!check[S.top()]){
			group_index++;

			reverse_dfs(S.top());
		}
		S.pop();
	}

	for(int i = 0; i < N; i++){

		work[i] = -BIG_NUM;
	}

	for(int i = 0; i < N; i++){
		for(int k = 0; k < reverse_G[i].size(); k++){
			int tmp_node = reverse_G[i][k];

			if(tmp_node > i || table[i] != table[tmp_node])continue;

			work[i] = max(work[i],tmp_node);
		}
	}

	int tmp = -1;
	int ans = 0;

	for(int i = 0; i < N; i++){
		if(work[i] == -BIG_NUM)continue;
		if(tmp < work[i]){
			ans++;
			tmp = i;
		}
	}

	printf("%d\n",ans);

	return 0;
}