#include <bits/stdc++.h>
using namespace std;
int parent[210];
int find(int v) {
  if (v != parent[v]) {
    return parent[v] = find(parent[v]);
  }
  return parent[v];
}
void unioni(int a, int b) {
  int pa = find(a);
  int pb = find(b);
  if (pa == pb) return;
  parent[pb] = pa;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= (n + m); ++i) {
    parent[i] = i;
  }
  int zero = 0;
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    if (x == 0)
      ++zero;
    else {
      for (int j = 1; j <= x; ++j) {
        int y;
        cin >> y;
        y += n;
        unioni(i, y);
      }
    }
  }
  set<int> ans;
  for (int i = 1; i <= n; ++i) {
    int x = find(i);
    ans.insert(x);
  }
  if ((ans.size() - 1) >= zero) {
    cout << ans.size() - 1 << endl;
  } else {
    cout << zero << endl;
  }
}
