#include <bits/stdc++.h>
using namespace std;
int p[105];
int a[105][105];
bool f[105];
int find(int x) {
  if (x != p[x]) p[x] = find(p[x]);
  return p[x];
}
bool issame(int x, int y) {
  for (int i = 1; i <= a[x][0]; i++)
    if (y == a[x][i]) return true;
  return false;
}
void deal(int x, int y) {
  int xx;
  for (int i = 1; i <= a[y][0]; i++) {
    if (!issame(x, a[y][i])) {
      a[x][0]++;
      xx = a[x][0];
      a[x][xx] = a[y][i];
    }
  }
  f[y] = 1;
}
bool isadd(int x, int y) {
  for (int i = 1; i <= a[x][0]; i++) {
    for (int j = 1; j <= a[y][0]; j++) {
      if (a[x][i] == a[y][j]) {
        return true;
      }
    }
  }
  return false;
}
int main() {
  int n, m;
  int x;
  int xx, yy;
  bool ff;
  while (~scanf("%d %d", &n, &m)) {
    ff = 0;
    for (int i = 1; i <= n; i++) {
      f[i] = 0;
      p[i] = i;
    }
    memset(a, 0, sizeof(a));
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i][0]);
      if (a[i][0]) ff = 1;
      for (int j = 1; j <= a[i][0]; j++) {
        scanf("%d", &a[i][j]);
      }
    }
    for (int i = 1; i <= n; i++) {
      if (f[i]) continue;
      for (int j = i + 1; j <= n; j++) {
        if (isadd(i, j)) {
          xx = find(i);
          yy = find(j);
          p[yy] = xx;
          deal(i, yy);
        }
      }
    }
    memset(f, 0, sizeof(f));
    int num = 0;
    for (int i = 1; i <= n; i++) {
      xx = find(i);
      if (!f[xx]) {
        num++;
        f[xx] = 1;
      }
    }
    if (!ff)
      cout << n << endl;
    else
      cout << num - 1 << endl;
  }
  return 0;
}
