#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f, mod = 1e9 + 7;
const double PI = acos(-1), EPS = 1e-8;
int dr[]{-1, -1, 0, 1, 1, 1, 0, -1};
int dc[]{0, 1, 1, 1, 0, -1, -1, -1};
void run() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
vector<int> adj[210];
bitset<210> vis;
void dfs(int node) {
  vis[node] = 1;
  for (int child : adj[node])
    if (!vis[child]) dfs(child);
}
int main() {
  run();
  int n, m;
  cin >> n >> m;
  int c = 0;
  for (int i = 1; i <= n; i++) {
    cin >> m;
    c += m;
    while (m--) {
      int x;
      cin >> x;
      x += 100;
      adj[i].push_back(x);
      adj[x].push_back(i);
    }
  }
  if (c == 0) return cout << n, 0;
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      cnt++;
      dfs(i);
    }
  }
  return cout << cnt - 1, 0;
}
