#include <bits/stdc++.h>
using namespace std;
const int N = 2e2;
vector<int> adj[N];
bool mark[N];
void dfs(int v) {
  mark[v] = true;
  for (int u : adj[v]) {
    if (!mark[u]) {
      dfs(u);
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    for (int j = 0; j < t; j++) {
      int x;
      cin >> x;
      sum += x;
      adj[i].push_back(n + x - 1);
      adj[n + x - 1].push_back(i);
    }
  }
  int cmp = 0;
  if (sum > 0) {
    for (int i = 0; i < n; i++) {
      if (!mark[i]) {
        cmp++;
        dfs(i);
      }
    }
  } else {
    cmp = n + 1;
  }
  cout << cmp - 1 << endl;
  return 0;
}
