#include <bits/stdc++.h>
using namespace std;
const long long c = 200, inf = 2000000000;
bool vis1[c], vis2[c];
int a[c][c], b[c][c], n, m, res = 0, p[c];
void dfs(int u, int q) {
  if (q == 1) {
    vis1[u] = 1;
    for (int i = 1; i <= m; i++)
      if (!vis2[i] && a[u][i]) dfs(i, 2);
  } else {
    vis2[u] = 1;
    for (int i = 1; i <= n; i++)
      if (!vis1[i] && b[u][i]) dfs(i, 1);
  }
}
int main() {
  memset(vis2, 0, sizeof(vis2));
  memset(a, 0, sizeof(a));
  memset(b, 0, sizeof(b));
  memset(vis1, 0, sizeof(vis1));
  cin >> n >> m;
  for (int k = 1; k <= n; k++) {
    cin >> p[k];
    for (int i = 1; i <= p[k]; i++) {
      int x;
      cin >> x;
      a[k][x] = 1;
      b[x][k] = 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!vis1[i] && p[i]) {
      res++;
      dfs(i, 1);
    }
    if (p[i] == 0) res++;
  }
  for (int i = 1; i <= n; i++)
    if (p[i]) {
      res--;
      break;
    }
  cout << res;
  return 0;
}
