#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 + 10;
bool mark[maxn];
vector<int> adj[maxn];
void dfs(int v) {
  mark[v] = true;
  for (int i = 0; i < (int)adj[v].size(); i++)
    if (!mark[adj[v][i]]) dfs(adj[v][i]);
}
int main() {
  fill(mark, mark + maxn, false);
  int m, n;
  cin >> n >> m;
  vector<int> zaban[n];
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a;
    for (int j = 0; j < a; j++) {
      cin >> b;
      zaban[i].push_back(b);
    }
  }
  for (int i = 1; i < n; i++)
    for (int j = 0; j < i; j++) {
      bool ok = false;
      for (int x = 0; x < zaban[i].size(); x++)
        for (int y = 0; y < zaban[j].size(); y++)
          if (zaban[i][x] == zaban[j][y]) {
            ok = true;
            goto no;
          }
    no:
      if (ok) {
        adj[i].push_back(j);
        adj[j].push_back(i);
      }
    }
  int ans = 0;
  bool kol = true;
  for (int i = 0; i < n; i++)
    if (zaban[i].size() != 0) {
      kol = false;
      break;
    }
  if (kol) {
    cout << n << endl;
    return 0;
  }
  while (true) {
    dfs(0);
    bool ok = true;
    for (int i = 0; i < n; i++)
      if (!mark[i]) {
        ok = false;
        ans++;
        dfs(i);
      }
    if (ok) break;
  }
  cout << ans << endl;
}
