#include <bits/stdc++.h>
using namespace std;
int n, m, kol[111], ans, col[111];
bool d[111][111];
vector<int> a[111];
inline void dfs(int u) {
  if (col[u]) return;
  col[u] = ans;
  for (int i = 0; i < a[u].size(); i++) {
    int t = a[u][i];
    dfs(t);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  bool zzz = false;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &kol[i]);
    if (kol[i]) zzz = true;
    for (int j = 1; j <= kol[i]; j++) {
      int x;
      scanf("%d", &x);
      d[i][x] = true;
    }
  }
  if (!zzz) {
    printf("%d\n", n);
    return 0;
  }
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++) {
      bool was = false;
      for (int k = 1; k <= m; k++)
        if (d[i][k] && d[j][k]) {
          was = true;
          break;
        }
      if (was) {
        a[i].push_back(j);
        a[j].push_back(i);
      }
    }
  for (int i = 1; i <= n; i++)
    if (!col[i]) {
      ans++;
      dfs(i);
    }
  cout << ans - 1 << endl;
  return 0;
}
