#include <bits/stdc++.h>
using namespace std;
using ll = long long;
inline int RI() {
  int ret = 0, flag = 1, ip = getchar();
  for (; ip < 48 || ip > 57; ip = getchar()) {
    if (ip == 45) {
      flag = -1;
      ip = getchar();
      break;
    }
  }
  for (; ip > 47 && ip < 58; ip = getchar()) ret = ret * 10 + ip - 48;
  return flag * ret;
}
vector<int> G[205];
bool vis[205];
void dfs(int u) {
  vis[u] = 1;
  for (int v : G[u]) {
    if (!vis[v]) {
      dfs(v);
    }
  }
}
int main() {
  int n, m, x, v, cnt, fl;
  while (cin >> n >> m) {
    for (int i = 0; i < 205; i++) G[i].clear();
    fl = 0;
    for (int i = 1; i <= n; i++) {
      cin >> x;
      fl |= x;
      while (x--) {
        cin >> v;
        G[i].push_back(v + n);
        G[v + n].push_back(i);
      }
    }
    cnt = 0;
    memset(vis, 0, sizeof vis);
    for (int i = 1; i <= n; i++) {
      if (!vis[i]) {
        dfs(i);
        cnt++;
      }
    }
    fl = fl ? 0 : 1;
    cout << max(cnt - 1 + fl, 0) << "\n";
  }
  return 0;
}
