#include <bits/stdc++.h>
using namespace std;
#define int long long
void run() {
int n;
cin >> n;
vector<int> g[n + 1];
for (int i = 1; i <= n; i++) {
int k;
cin >> k;
while (k--) {
int j;
cin >> j;
g[j].push_back(i);
}
}
int ans = 1e18;
for (int root = 1; root <= n; root++) {
bool vis[n + 1];
int cur = 0;
fill_n(vis, n + 1, false);
function<int(int)> dfs = [&](int u) {
vis[u] = true;
int res = 1;
for (int v : g[u]) {
if (!vis[v]) {
res += dfs(v);
}
}
cur += res;
return res;
};
dfs(root);
bool ok = true;
for (int i = 1; i <= n; i++) {
if (!vis[i]) {
ok = false;
break;
}
}
if (ok) {
ans = min(ans, cur);
}
}
cout << ans << '\n';
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(nullptr);
int t = 1;
while (t--) {
run();
}
}