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 <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<vector<int> > A(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		int M;
		cin >> M;
		int a;
		for (int j = 0; j < M; j++) {
			cin >> a;
			a--;
			A[i].push_back(a);
		}
		sort(A[i].begin(), A[i].end());
		A[i].erase(unique(A[i].begin(), A[i].end()), A[i].end());
	}
	int mx = -1;
	vector<int> E(N, 1);
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < A[i].size(); j++) {
			if (A[i][j] == i) {
				E[i] = 0;
				break;
			}
		}
	}
	for (int i = N - 1; i >= 0; i--) {
		if (E[i] == 0) {
			mx = -1;
		}
		else if ((int)A[i].size() == 0) {
			res++;
			mx = -1;
		}
		else if (A[i].back() == i + 1 && E[i + 1] == 1) {
			if (mx == i) {
				mx = -1;
				E[i] = 0;
				//cerr << "erase " << i << endl;
			}
			else {
				int x = (int)A[i].size() - 2;
				while (x >= 0 && E[A[i][x]] == 0) {
					x--;
				}
				if (x >= 0) {
					mx = max(mx, A[i][x]);
				}
				res++;
			}
		}
		else {
			res++;
			int x = (int)A[i].size() - 1;
			while (x >= 0 && E[A[i][x]] == 0) {
				x--;
			}
			if (x >= 0) {
				mx = A[i][x];
			}
		}
	}
	cout << N - res << endl;
}