#include <bits/stdc++.h>
using namespace std;
int n, i, j, f, s, m, ans;
int a[305][305], t[305];
bool used[305];
vector<vector<int> > use(10005);
void dfs(int x) {
  used[x] = 1;
  for (int i = 1; i <= t[x]; i++) {
    int l1 = use[a[x][i]].size();
    for (int j = 0; j < l1; j++) {
      if (!used[use[a[x][i]][j]]) {
        dfs(use[a[x][i]][j]);
      }
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) {
    scanf("%d", &t[i]);
    if (t[i] != 0) {
      f = 1;
    }
    for (j = 1; j <= t[i]; j++) {
      scanf("%d", &a[i][j]);
      use[a[i][j]].push_back(i);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!used[i]) {
      dfs(i);
      ans++;
    }
  }
  if (f != 0) {
    ans -= 1;
  }
  printf("%d\n", ans);
  return 0;
}
