#include <bits/stdc++.h>
using namespace std;
int a[101] = {0};
int p[101][101] = {0};
int n, m;
int pa[101] = {0};
int temp = 0;
void update(int v, int i) {
  if (a[v] == 0) {
    a[v] = i;
  } else {
    int t = a[v];
    for (int j = 1; j <= n; j++) {
      if (a[j] == t) {
        a[j] = i;
      }
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    int k;
    cin >> k;
    p[i][0] = k;
    for (int j = 1; j <= k; j++) {
      cin >> p[i][j];
      int t = p[i][j];
      update(t, i);
    }
  }
  int an = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] != 0) {
      if (pa[a[i]] == 0) {
        pa[a[i]] = 1;
        an++;
      }
    }
  }
  an--;
  if (an < 0) {
    cout << n << endl;
  } else {
    for (int i = 1; i <= n; i++) {
      int k = p[i][0];
      int flag = 1;
      for (int j = 1; j <= k; j++) {
        int t = p[i][j];
        if (a[t] == 0) {
          flag = 1;
        } else {
          flag = 0;
          break;
        }
      }
      if (flag == 1) {
        an++;
      }
    }
    cout << an << endl;
  }
  return 0;
}
