#include <bits/stdc++.h>
using namespace std;
long long n, m;
vector<long long> a[201];
long long vis[201] = {0};
void dfs(int u, int f) {
  vis[u] = 1;
  for (auto x : a[u]) {
    if (x == f or vis[x]) continue;
    dfs(x, u);
  }
}
int main() {
  cin >> n >> m;
  long long c = 0;
  for (long long i = 1; i < n + 1; i++) {
    int k;
    cin >> k;
    if (!k) c++;
    for (long long j = 0; j < k; j++) {
      int x;
      cin >> x;
      a[100 + i].push_back(x);
      a[x].push_back(100 + i);
    }
  }
  long long ans = 0;
  for (long long i = 101; i < 100 + n + 1; i++) {
    if (vis[i] == 0) {
      ans++;
      dfs(i, 0);
    }
  }
  if (c == n)
    cout << ans << endl;
  else
    cout << ans - 1 << endl;
  return 0;
}
