The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official languages. But the employees are willing to learn any number of official languages, as long as the company pays their lessons. A study course in one language for one employee costs 1 berdollar.

Find the minimum sum of money the company needs to spend so as any employee could correspond to any other one (their correspondence can be indirect, i. e. other employees can help out translating).

Input

The first line contains two integers n and m (2 ≤ n, m ≤ 100) — the number of employees and the number of languages.

Then n lines follow — each employee's language list. At the beginning of the i-th line is integer ki (0 ≤ ki ≤ m) — the number of languages the i-th employee knows. Next, the i-th line contains ki integers — aij (1 ≤ aij ≤ m) — the identifiers of languages the i-th employee knows. It is guaranteed that all the identifiers in one list are distinct. Note that an employee may know zero languages.

The numbers in the lines are separated by single spaces.

Output

Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating).

Examples

Input

5 5
1 2
2 2 3
2 3 4
2 4 5
1 5


Output

0


Input

8 7
0
3 1 2 3
1 1
2 5 4
2 6 7
1 3
2 7 4
1 1


Output

2


Input

2 2
1 2
0


Output

1

Note

In the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.

In the third sample employee 2 must learn language 2.
#include <bits/stdc++.h>
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
const int INF = 1 << 29;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n >> b) & 1; }
inline void set_bit(int &n, int b) { n |= two(b); }
inline void unset_bit(int &n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) {
  int res = 0;
  while (n && ++res) n -= n & (-n);
  return res;
}
template <class T>
void chmax(T &a, const T &b) {
  a = max(a, b);
}
template <class T>
void chmin(T &a, const T &b) {
  a = min(a, b);
}
long long gcd(long long a, long long b) {
  if (a == 0 || b == 0) return 0;
  if (a == b) return a;
  if (a > b) return gcd(a - b, b);
  return gcd(a, b - a);
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
long long max(long long a, long long b) {
  if (a > b) return a;
  return b;
}
long long power(long long x, long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = res * x;
    y = y >> 1;
    x = x * x;
  }
  return res;
}
long long powermod(long long x, long long y) {
  long long res = 1;
  x = x % 1000000007;
  while (y > 0) {
    if (y & 1) res = (res * x) % 1000000007;
    y = y >> 1;
    x = (x * x) % 1000000007;
  }
  return res;
}
long long mulmod(long long a, long long b) {
  long long res = 0;
  a %= 1000000007;
  while (b) {
    if (b & 1) res = (res + a) % 1000000007;
    a = (2 * a) % 1000000007;
    b >>= 1;
  }
  return res;
}
bool isPrime(long long n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (int i = 5; i * i <= n; i += 6) {
    if ((n % i == 0) || (n % (i + 2) == 0)) return false;
  }
  return true;
}
long double dist(long long x1, long long y1, long long x2, long long y2) {
  return (long double)sqrt(
      (long double)((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)));
}
long long squaredist(long long x1, long long y1, long long x2, long long y2) {
  return ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
long long nCr(long long n, long long r) {
  if (r == 0) return 1;
  return (n * nCr(n - 1, r - 1)) / r;
}
long long countDivisors(long long n) {
  long long cnt = 0;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (n / i == i)
        cnt++;
      else
        cnt = cnt + 2;
    }
  }
  return cnt;
}
long long modulo(long long a, long long b) {
  long long r = a % b;
  return r < 0 ? r + b : r;
}
using namespace std;
class Graph {
  long long n;
  vector<vector<long long>> adj;
  vector<bool> visited;
  vector<long long> dis, parent;

 public:
  Graph(long long n, long long N);
  long long comp = 0;
  bool flag = false;
  long long N;
  void addEdge(long long v, long long w);
  void dfs();
  void dfsVisit(long long v);
};
Graph::Graph(long long n, long long N) {
  this->n = n;
  this->N = N;
  adj.resize(n);
  visited.resize(n, false);
  dis.resize(n);
  parent.resize(n);
}
void Graph::addEdge(long long v, long long w) {
  adj[v].push_back(w);
  adj[w].push_back(v);
}
void Graph::dfs() {
  for (long long i = 0; i < n; i++) {
    if (!visited[i]) {
      flag = false;
      parent[i] = -1;
      if (i <= N - 1) {
        flag = true;
        comp++;
      }
      dfsVisit(i);
    }
  }
}
void Graph::dfsVisit(long long v) {
  visited[v] = true;
  for (long long u : adj[v]) {
    if (!visited[u]) {
      if (!flag && u <= N - 1) {
        flag = true;
        comp++;
      }
      parent[u] = v;
      dfsVisit(u);
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  long long oc = 0;
  Graph g(n + m, n);
  for (long long i = 0; i < (n); i++) {
    long long c;
    cin >> c;
    if (!c) {
      oc++;
    }
    for (long long j = 0; j < (c); j++) {
      long long z;
      cin >> z;
      g.addEdge(i, n + z - 1);
    }
  }
  if (oc == n) {
    cout << n;
    return 0;
  }
  g.dfs();
  cout << g.comp - 1;
  return 0;
}
