#include <bits/stdc++.h>
using namespace std;
long long parent[101] = {0};
long long set_size[101] = {0};
void make_set(long long v) {
  parent[v] = v;
  set_size[v] = 1;
}
long long find_set(long long v) {
  if (v == parent[v]) return v;
  return parent[v] = find_set(parent[v]);
}
void union_sets(long long a, long long b) {
  a = find_set(a);
  b = find_set(b);
  if (a != b) {
    if (set_size[a] < set_size[b]) {
      parent[a] = b;
      set_size[b] += set_size[a];
    } else {
      parent[b] = a;
      set_size[a] += set_size[b];
    }
  }
}
int32_t main() {
  long long n, m;
  cin >> n >> m;
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    long long a;
    cin >> a;
    if (a == 0) {
      ans++;
    } else {
      long long temp = 0;
      for (long long j = 0; j < a; j++) {
        long long b;
        cin >> b;
        if (parent[b] == 0) parent[b] = b;
        if (temp == 0) {
          temp = b;
        } else {
          union_sets(temp, b);
          temp = b;
        }
      }
    }
  }
  long long temp = 0;
  for (long long i = 1; i <= m; i++) {
    if (find_set(i) == i) {
      temp++;
    }
  }
  if (temp > 0) temp--;
  cout << ans + temp << endl;
  return 0;
}
