#include <bits/stdc++.h>
using namespace std;
int n, m, k, s, i, j, x;
vector<int> a[101];
vector<int> c[101];
bool Incl[101];
void DFS(int x) {
  int ii, jj;
  for (ii = 0; ii < a[x].size(); ii++) {
    for (jj = 0; jj < c[a[x][ii]].size(); jj++) {
      if (!Incl[c[a[x][ii]][jj]]) {
        Incl[c[a[x][ii]][jj]] = true;
        DFS(c[a[x][ii]][jj]);
      }
    }
  }
}
int main() {
  int p;
  s = 0;
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    cin >> k;
    if (k == 0) {
      s++;
      Incl[i] = true;
    }
    for (j = 1; j <= k; j++) {
      cin >> x;
      a[i].push_back(x);
      c[x].push_back(i);
    }
  }
  p = 0;
  for (i = 1; i <= n; i++) {
    if (!Incl[i]) {
      Incl[i] = true;
      DFS(i);
      s++;
      p = 1;
    }
  }
  cout << s - p << endl;
  return 0;
}
