#include <bits/stdc++.h>
using namespace std;
const int maxn = 205;
vector<int> adj[maxn];
bool mark[maxn];
int par[maxn];
void dfs(int v) {
  mark[v] = true;
  int u;
  for (int i = 0; i < adj[v].size(); i++) {
    u = adj[v][i];
    if (!mark[u]) {
      par[u] = v;
      dfs(u);
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  int x = n;
  int y = 0;
  while (n--) {
    int k;
    cin >> k;
    if (k == 0) y++;
    int a[k];
    for (int i = 0; i < k; i++) {
      cin >> a[i];
      a[i] = a[i] + x;
      adj[a[i]].push_back(n);
      adj[n].push_back(a[i]);
    }
  }
  int cnt = 0;
  for (int i = 0; i < x; i++) {
    if (mark[i] == false) {
      par[i] = -1;
      dfs(i);
      cnt++;
    }
  }
  if (y == x) {
    cout << x;
    return 0;
  } else {
    cnt--;
    cout << cnt;
  }
  return 0;
}
