#include <bits/stdc++.h>
using namespace std;
int f[2005], a[2005] = {0};
int find(int x) {
  if (x == f[x]) return x;
  return f[x] = find(f[x]);
}
void init() {
  for (int i = 0; i <= 200; i++) f[i] = i;
}
void Union(int x, int y) { f[y] = x; }
int main() {
  int n, m;
  int cnt = 0;
  cin >> n >> m;
  init();
  for (int i = 1; i <= n; i++) {
    int t;
    scanf("%d", &t);
    if (t == 0) {
      a[i] = 1;
      cnt++;
      continue;
    }
    for (int j = 1; j <= t; j++) {
      int a;
      scanf("%d", &a);
      int fx = find(i);
      int fy = find(n + a);
      if (fx != fy) Union(fx, fy);
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (!a[i])
      if (i == find(i)) ans++;
  }
  if (ans == 0) ans = 1;
  cout << cnt + ans - 1 << endl;
  return 0;
}
