#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
int n, m, N, ans, x;
bool used[200][200], Used[200];
vector<int> g[200], G[200];
void dfs(int v) {
  Used[v] = true;
  for (int i = 0; i < G[v].size(); i++)
    if (!Used[G[v][i]]) dfs(G[v][i]);
}
int main() {
  bool D = false;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &N);
    if (N) D = true;
    for (int j = 1; j <= N; j++)
      scanf("%d", &x), g[i].push_back(x), used[i][x] = true;
  }
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++) {
      bool ind = false;
      for (int k = 0; k < g[i].size(); k++)
        if (used[j][g[i][k]]) {
          ind = true;
          break;
        }
      if (ind) G[i].push_back(j), G[j].push_back(i);
    }
  for (int i = 1; i <= n; i++)
    if (!Used[i]) ans++, dfs(i);
  if (!D)
    cout << n << endl;
  else
    cout << ans - 1 << endl;
}
