#include <bits/stdc++.h>
using namespace std;
int counter;
bool visited[101], used[101];
vector<vector<int> > graph;
void dfs(int node) {
  if (visited[node]) return;
  visited[node] = 1;
  for (int i = 0; i < graph[node].size(); i++) dfs(graph[node][i]);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  bool first = true;
  int n, m, temp, a, b;
  cin >> n >> m;
  graph.resize(m + 1);
  while (n--) {
    cin >> temp;
    if (temp == 0)
      counter++;
    else if (temp == 1)
      cin >> a, used[a] = 1;
    else {
      cin >> a;
      while (--temp) {
        cin >> b;
        used[a] = used[b] = 1;
        graph[a].push_back(b);
        graph[b].push_back(a);
        a = b;
      }
    }
  }
  for (int i = 1; i <= m; i++)
    if (first && used[i] && !visited[i])
      dfs(i), first = !first;
    else if (!first && used[i] && !visited[i])
      dfs(i), counter++;
  cout << counter << endl;
  return 0;
}
