#include <bits/stdc++.h>
using namespace std;
int n, m, cnt, x, arr[101], a, f;
vector<vector<int> > adj;
bool done[102][102], d5l[102];
int vis[102];
void dfs(int node) {
  vis[node] = true;
  for (int i = 0; i < adj[node].size(); i++) {
    if (!vis[adj[node][i]]) dfs(adj[node][i]);
  }
}
int connected_com() {
  int c = 0;
  for (int i = 0; i < m; i++) {
    if (!vis[i] && d5l[i]) c++, dfs(i);
  }
  return max(0, c - 1);
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  adj = vector<vector<int> >(m);
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (!x)
      cnt++;
    else {
      x--;
      cin >> a;
      d5l[a - 1] = true;
      for (int j = 0; j < x; j++) {
        cin >> f;
        d5l[f - 1] = true;
        if (done[a - 1][f - 1]) continue;
        adj[a - 1].push_back(f - 1);
        adj[f - 1].push_back(a - 1);
        done[a - 1][f - 1] = done[f - 1][a - 1] = true;
      }
    }
  }
  cout << cnt + connected_com() << "\n";
  return 0;
}
