#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long qpow(long long a, long long b, long long mod) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % mod;
    b >>= 1;
    a = (a * a) % mod;
  }
  return ans;
}
long long qmul(long long a, long long b, long long mod) {
  long long ans = 0;
  while (b > 0) {
    if (b & 1) ans = (ans + a) % mod;
    b >>= 1;
    a = (a + a) % mod;
  }
  return ans;
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
using namespace std;
const int maxn = 110;
int mem[maxn];
int f[maxn];
int p[maxn];
int n, m;
int find(int x) {
  while (x != f[x]) x = f[x];
  return x;
}
int merge(int x, int y) {
  int fx, fy;
  fx = find(x);
  fy = find(y);
  if (fx != fy) f[fx] = fy;
}
signed main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) f[i] = i;
  for (int i = 1; i <= n; i++) {
    int q;
    cin >> q;
    if (q == 0) p[i] = 1;
    while (q--) {
      int a;
      cin >> a;
      if (mem[a] != 0) {
        merge(mem[a], i);
        continue;
      }
      mem[a] = i;
    }
  }
  int cnt1 = 0, cnt2 = 0;
  for (int i = 1; i <= n; i++)
    if (f[i] == i && p[i]) cnt1++;
  for (int i = 1; i <= n; i++)
    if (f[i] == i && !p[i]) cnt2++;
  if (cnt2 > 1) cnt1 += (cnt2 - 1);
  cout << cnt1 << '\n';
  return 0;
}
