#include <bits/stdc++.h>
int q[100];
int find(int i) {
  if (q[i] == i) return i;
  return find(q[i]);
}
void un(int i, int j) {
  int i1 = find(i);
  int j1 = find(j);
  if (i1 != j1) {
    q[i1] = j1;
  }
}
void solve(int n) {
  int i, j, k = 0, l[101][101], p, m, i1;
  scanf("%d", &m);
  for (i = 0; i < n; i++)
    for (j = 0; j < 100; j++) l[i][j] = 0;
  for (i = 0; i < n; i++) {
    scanf("%d", &l[i][0]);
    q[i] = i;
    for (j = 0; j < l[i][0]; j++) {
      scanf("%d", &p);
      l[i][p] = 1;
      k = p;
    }
  }
  if (k == 0) {
    printf("%d\n", n);
    return;
  }
  p = 0;
  for (i = 0; i < n; i++)
    if (l[i][0] == 0) {
      l[i][k] = 1;
      p++;
      l[i][0] = 1;
    }
  for (i = 1; i <= 100; i++)
    for (j = 0; j < n; j++)
      for (k = j + 1; k < n; k++)
        if (l[j][i] == 1 && l[k][i] == 1) {
          un(j, k);
        }
  for (i = 0; i < 101; i++) l[i][0] = 0;
  for (i = 0; i < n; i++) l[find(i)][0] = 1;
  p--;
  for (i = 0; i < 101; i++) p += l[i][0];
  printf("%d\n", p);
}
int main() {
#pragma comment(linker, "/STACK:268435456")
  int n, i;
  while (scanf("%d", &n) != EOF) {
    solve(n);
  }
  return 0;
}
