#include <bits/stdc++.h>
using namespace std;
const long long dx[] = {-1, -1, -1, 0, 1, 1, 1, 0};
const long long dy[] = {-1, 0, 1, 1, 1, 0, -1, -1};
long long n, m, i;
const long long N = 3e2 + 5;
vector<long long> edge[N];
bool vis[N];
void dfs(long long x) {
  vis[x] = 1;
  for (auto a : edge[x]) {
    if (!vis[a]) dfs(a);
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t = 1;
  while (t--) {
    cin >> n >> m;
    long long zer = 0;
    for (i = 1; i <= n; i++) {
      long long x;
      cin >> x;
      if (x == 0) zer++;
      for (long long j = 1; j <= x; j++) {
        long long lang;
        cin >> lang;
        edge[i].push_back(lang + 200);
        edge[lang + 200].push_back(i);
      }
    }
    long long count = 0;
    for (i = 1; i <= n; i++) {
      if (!vis[i]) {
        dfs(i);
        count++;
      }
    }
    if (zer != n)
      cout << count - 1 << '\n';
    else
      cout << n << '\n';
  }
  return 0;
}
