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>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))

#define MOD 1000000007

int n,m;
set<int> g[125252];

int sm[125252];
vector<int> eds[125252];

int main(){
  scanf("%d",&n);
  REP(i,n){
    scanf("%d",&m);
    while(m--){
      int x;
      scanf("%d",&x);
      g[i].insert(x-1);
    }
  }
  set<int> rm;
  REP(i,n)if(g[i].count(i)){
    rm.insert(i);
  }
  REP(i,n)if(!rm.count(i)){
    set<int>::iterator it = g[i].begin();
    while(it != g[i].end()){
      if(rm.count(*it)){
        g[i].erase(it++);
      }else{
        it++;
      }
    }
  }
  REP(i,n)if(!rm.count(i) && g[i].count(i+1)){
    sm[i+1]++;
  }
  REP(i,n+1)sm[i+1]+=sm[i];
  REP(i,n)if(!rm.count(i)){
    set<int>::iterator it = g[i].begin();
    while(it != g[i].end()){
      int x = *it; it++;
      int y = i;
      if(x==y+1)continue;
      assert(x<y);
      if(y-x == sm[y]-sm[x]){
        eds[x].push_back(y);
      }
    }
  }
  priority_queue<int> Q;
  int ans = rm.size();
  REP(i,n){
    for(int x : eds[i]){
      Q.push(-x);
    }
    if(Q.size() && -Q.top() == i){
      ans++;
      while(Q.size())Q.pop();
    }
  }
  printf("%d\n",ans);
  return 0;
}