#include <bits/stdc++.h>
template <class T>
inline T bigmod(T p, T e, T M) {
  long long int ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
template <class T>
inline T bpow(T p, T e) {
  long long int ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p);
    p = (p * p);
  }
  return (T)ret;
}
using namespace std;
const int MOD = (int)1e9 + 7;
vector<long long int> graph[110];
long long int visited[200] = {0};
set<long long int> node;
void dfs(int source) {
  if (visited[source]) return;
  visited[source] = 1;
  for (int i = 0; i < graph[source].size(); i++) {
    long long int u = graph[source][i];
    if (!visited[u]) {
      dfs(u);
    }
  }
}
void solve() {
  long long int n, m;
  cin >> n >> m;
  long long int ctn = 0;
  long long int ans = 0;
  for (long long int i = 1; i <= n; i++) {
    long long int x;
    cin >> x;
    if (x != 0) {
      long long int prothom;
      for (long long int k = 1; k <= x; k++) {
        long long int a;
        cin >> a;
        if (k == 1) {
          prothom = a;
          node.insert(a);
        } else {
          node.insert(a);
          graph[prothom].push_back(a);
          graph[a].push_back(prothom);
        }
      }
    } else
      ctn++;
  }
  for (auto it : node) {
    if (!visited[it]) {
      dfs(it);
      ans++;
    }
  }
  if (ans == 0)
    cout << ctn << endl;
  else
    cout << ctn + ans - 1 << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
