#include <bits/stdc++.h>
using namespace std;
int n, m, k, x, cnt, t, vis[101];
vector<vector<int> > L(101), E(101);
void DFS(int v) {
  vis[v] = 1;
  for (int i = 0; i < E[v].size(); i++)
    for (int j = 0; j < L[E[v][i]].size(); j++)
      if (!vis[L[E[v][i]][j]]) DFS(L[E[v][i]][j]);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &k);
    for (int j = 1; j <= k; j++) {
      scanf("%d", &x);
      L[x].push_back(i);
      E[i].push_back(x);
    }
    if (!k) t++;
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      cnt++;
      DFS(i);
    }
  }
  cout << cnt - 1 + (t == n);
  return 0;
}
