#include <bits/stdc++.h>
using namespace std;
const int sz = 1e2 + 9;
const long long mod = 1e9 + 7;
const long long inf = 1e9 + 5;
const double eps = 1e-6;
vector<int> adj[sz], lan[sz], vis(sz, 0);
int n, m, c = 0;
void dfs(int a) {
  vis[a] = 1;
  for (auto b : adj[a]) {
    for (auto child : lan[b]) {
      if (!vis[child]) dfs(child);
    }
  }
}
int main() {
  cin >> n >> m;
  bool f = 0;
  for (int i = 0; i < n; i++) {
    int s;
    scanf("%d", &s);
    while (s--) {
      int l;
      scanf("%d", &l);
      if (l) f = 1;
      adj[i + 1].push_back(l);
      lan[l].push_back(i + 1);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) c++, dfs(i);
  }
  if (!f)
    cout << n << endl;
  else
    cout << c - 1 << endl;
}
