#include <bits/stdc++.h>
using namespace std;
int a[105], c[105];
int findz(int n) { return a[n] == n ? a[n] : a[n] = findz(a[n]); }
void un(int x, int y) { a[findz(x)] = findz(y); }
int main() {
  int n, l, f;
  cin >> n >> l;
  int count = 0;
  int wei = 0;
  memset(c, 0, sizeof(c));
  for (int i = 1; i <= l; i++) a[i] = i;
  for (int i = 0; i < n; i++) {
    int z;
    cin >> z;
    if (z >= 1) {
      cin >> f;
      c[f]++;
    } else
      count++;
    for (int j = 1; j < z; j++) {
      int b;
      cin >> b;
      c[b]++;
      un(f, b);
    }
  }
  set<int> s;
  for (int i = 1; i <= l; i++) {
    s.insert(findz(i));
    if (c[i] == 0) wei++;
  }
  if (s.size() - wei == 0) {
    cout << count;
  } else {
    cout << count + s.size() - wei - 1;
  }
  return 0;
}
