#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<vector<int> > v;
  vector<int> cc;
  int n, m, i, j, k, temp, zc = 0;
  int vis[200];
  int flag = 0;
  int ans = 0;
  for (i = 0; i < 200; i++) vis[i] = 0;
  queue<int> qu;
  scanf("%d %d", &n, &m);
  for (i = 0; i < n; i++) v.push_back(cc);
  for (i = 0; i < n; i++) {
    scanf("%d", &k);
    if (k == 0) {
      zc++;
      vis[i] = 1;
    } else {
      for (j = 0; j < k; j++) {
        scanf("%d", &temp);
        v[i].push_back(temp);
      }
      if (flag == 0) {
        qu.push(i);
        vis[i] = 1;
        flag = 1;
      }
    }
  }
  while (!qu.empty()) {
    temp = qu.front();
    qu.pop();
    for (i = 0; i < v[temp].size(); i++) {
      for (j = 0; j < n; j++) {
        if (i != j && vis[j] == 0) {
          for (k = 0; k < v[j].size(); k++) {
            if (v[temp][i] == v[j][k]) {
              qu.push(j);
              vis[j] = 1;
            }
          }
        }
      }
    }
    if (qu.empty()) {
      for (i = 0; i < n; i++) {
        if (vis[i] == 0) {
          qu.push(i);
          vis[i] = 1;
          ans++;
          break;
        }
      }
    }
  }
  cout << ans + zc << endl;
  return 0;
}
