#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
long long sqr(long long a) { return a * a; }
struct gr {
  bool l[111];
};
long long n, m;
vector<gr> v;
gr g;
int main() {
  cin >> n >> m;
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    int k;
    cin >> k;
    for (int j = 1; j <= m; ++j) {
      g.l[j] = false;
    }
    for (int j = 0; j < k; ++j) {
      int x;
      cin >> x;
      g.l[x] = true;
    }
    if (k == 0) {
      ++ans;
    } else {
      v.push_back(g);
    }
  }
  for (int i = 0; i < v.size(); ++i) {
    if (i < v.size()) {
      for (int j = i + 1; j < v.size(); ++j) {
        bool good = false;
        for (int k = 1; k <= m; ++k) {
          if (v[i].l[k] == v[j].l[k] && v[i].l[k] == true) {
            good = true;
          }
        }
        if (good) {
          for (int k = 1; k <= m; ++k) {
            v[i].l[k] = v[i].l[k] || v[j].l[k];
          }
          v[j] = v.back();
          v.pop_back();
          j = i;
        }
      }
    }
  }
  if (v.size() != 0) {
    cout << v.size() - 1 + ans << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}
