#include <bits/stdc++.h>
using namespace std;
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};
void file() {}
void fast() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
}
int n, m;
vector<int> lang[200];
vector<int> v1[200];
bool vis[200];
void dfs(int u) {
  if (vis[u]) return;
  vis[u] = 1;
  for (int i = 0; i < (int)(v1[u].size()); i++) {
    for (auto v : lang[v1[u][i]]) dfs(v);
  }
}
int main() {
  file();
  fast();
  cin >> n >> m;
  int no = 0;
  for (int i = 1; i <= n; i++) {
    int w;
    cin >> w;
    if (!w) no++;
    while (w--) {
      int x;
      cin >> x;
      v1[i].push_back(x);
      lang[x].push_back(i);
    }
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (vis[i]) continue;
    dfs(i);
    cnt++;
  }
  if (no == n)
    cout << n << "\n";
  else
    cout << cnt - 1 << "\n";
  return 0;
}
