#include <bits/stdc++.h>
using namespace std;
int x, q;
vector<int> adj[205];
bool visited[205];
void dfs(int n) {
  visited[n] = 1;
  for (int i = 0; i < adj[n].size(); i++) {
    if (!visited[adj[n][i]]) {
      visited[adj[n][i]] = 1;
      dfs(adj[n][i]);
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  bool flag = 0;
  for (int i = m + 1; i <= n + m; i++) {
    cin >> q;
    while (q--) {
      cin >> x;
      if (x) {
        flag = 1;
      }
      adj[i].push_back(x);
      adj[x].push_back(i);
    }
  }
  if (!flag) {
    cout << n << endl;
    return 0;
  }
  int ans = -1;
  for (int i = m + 1; i <= n + m; i++) {
    if (!visited[i]) {
      dfs(i);
      ans++;
    }
  }
  cout << ans << endl;
}
