#include <bits/stdc++.h>
using namespace std;
bool a[101][101];
bool mark[101];
vector<int> KC[101], CK[101];
void cal(int e) {
  mark[e] = 1;
  for (int i = 0; i < KC[e].size(); i++)
    for (int j = 0; j < CK[KC[e][i]].size(); j++)
      if (!mark[CK[KC[e][i]][j]]) cal(CK[KC[e][i]][j]);
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int p;
      cin >> p;
      KC[i].push_back(p);
      CK[p].push_back(i);
    }
  }
  int res1 = 0, res2 = 0;
  for (int i = 0; i < n; i++) {
    if (KC[i].size() == 0)
      res2++;
    else if (!mark[i]) {
      cal(i);
      res1++;
    }
  }
  cout << res2 + max(res1 - 1, 0) << endl;
}
