#include <bits/stdc++.h>
using namespace std;
vector<int> G[300];
map<int, bool> mapa;
bool seen[400];
void dfs(int u) {
  seen[u] = 1;
  for (int i = 0; i < int(G[u].size()); i++) {
    int v = G[u][i];
    if (seen[v] == 0) {
      seen[v] = 1;
      dfs(v);
    }
  }
}
int main() {
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < int(N); i++) {
    int n;
    cin >> n;
    if (n == 0) mapa[i] = 1;
    for (int j = 0; j < int(n); j++) {
      int a;
      cin >> a;
      G[i].push_back(a + N + 1);
      G[a + N + 1].push_back(i);
    }
  }
  memset(seen, 0, sizeof seen);
  int k = 0;
  for (int i = 0; i < int(N); i++) {
    if (seen[i] == 0 and mapa.count(i) == 0) {
      dfs(i);
      k++;
    }
  }
  if (k > 0)
    cout << k + mapa.size() - 1 << endl;
  else
    cout << mapa.size() << endl;
  return 0;
}
