#include <bits/stdc++.h>
using namespace std;
int r[500];
int Find(int a) { return r[a] > 0 ? r[a] = Find(r[a]) : a; }
bool Union(int a, int b) {
  a = Find(a);
  b = Find(b);
  return a ^ b ? r[a] < r[b] ? (r[a] += --r[b], r[b] = a)
                             : (r[b] += --r[a], r[a] = b)
               : 0;
}
int main() {
  int n, m;
  cin >> n >> m;
  int zeros = 0;
  for (int i = 0; i < n; ++i) {
    int k;
    cin >> k;
    if (k == 0) zeros++;
    for (int j = 0; j < k; ++j) {
      int a;
      cin >> a;
      Union(i, a + 200);
    }
  }
  set<int> uniq;
  for (int i = 0; i < n; ++i) {
    if (r[i]) uniq.insert(Find(i));
  }
  if (zeros == n)
    cout << n << endl;
  else
    cout << uniq.size() - 1 + zeros << endl;
}
