#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e+9;
const int MAX_N = 2e5 + 7;
bool mark[100];
vector<int> lang[100], peop[100];
int ppl, l;
int ans = 0;
int m_c = 0;
void random_lang() {
  for (int index = 0; index < ppl; index++) {
    if (peop[index].size() == 0)
      for (int i = 0; i < l; i++)
        if (lang[i].size() > 0 || i == l - 1) {
          lang[i].push_back(index);
          peop[index].push_back(i);
          ans++;
          break;
        }
  }
}
void dfs(int index) {
  mark[index] = true;
  m_c++;
  for (int i = 0; i < peop[index].size(); i++) {
    int my_l = peop[index][i];
    for (int j = 0; j < lang[my_l].size(); j++) {
      int new_ppl = lang[my_l][j];
      if (!mark[new_ppl]) dfs(new_ppl);
    }
  }
  if (index == 0 && m_c != ppl)
    for (int i = 0; i < ppl; i++)
      if (!mark[i]) {
        dfs(i);
        ans++;
      }
}
int main() {
  memset(mark, false, sizeof(mark));
  cin >> ppl >> l;
  for (int i = 0; i < ppl; i++) {
    int my_l;
    cin >> my_l;
    for (int j = 0; j < my_l; j++) {
      int new_l;
      cin >> new_l;
      lang[--new_l].push_back(i);
      peop[i].push_back(new_l);
    }
  }
  random_lang();
  dfs(0);
  cout << ans;
  return 0;
}
