#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long fir, long long sec) {
  return (fir * sec) / (gcd(fir, sec));
}
long long modularExponentiation(long long x, long long n, long long M) {
  if (n == 0)
    return 1;
  else if (n % 2 == 0)
    return modularExponentiation((x * x) % M, n / 2, M);
  else
    return (x * modularExponentiation((x * x) % M, (n - 1) / 2, M)) % M;
}
const int MOD = 1e6 + 7;
const string small_alphabets = "abcdefghijklmnopqrstuvwxyz";
const int month_days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
vector<int> v[102];
bool arr[102][102];
bool visited[102];
void dfs(int x) {
  visited[x] = true;
  for (int i = 0; i < v[x].size(); ++i) {
    if (!visited[v[x][i]]) {
      int n = v[x][i];
      dfs(n);
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  memset(arr, false, sizeof arr);
  memset(visited, false, sizeof visited);
  int x;
  int y;
  int zer = 0;
  for (int i = 0; i < n; ++i) {
    cin >> x;
    if (x == 0) {
      zer++;
    }
    for (int j = 0; j < x; ++j) {
      cin >> y;
      arr[i + 1][y] = true;
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= 100; ++j) {
      if (arr[i][j]) {
        for (int k = 1; k <= 100; ++k) {
          if (arr[k][j]) {
            v[i].push_back(k);
          }
        }
      }
    }
  }
  int cc = 0;
  for (int i = 1; i <= n; ++i) {
    if (!visited[i]) {
      cc++;
      dfs(i);
    }
  }
  cout << max(zer, cc - 1) << endl;
  ;
  return 0;
}
