PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#DSU0000028. Học ngôn ngữ (Learning Languages)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Học ngôn ngữ (Learning Languages)

Learning Languages

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

A company employs nn people and uses mm languages numbered from 11 to mm. Every employee knows some of these languages, possibly none.

Two employees can communicate directly if they share a language. Communication may also be indirect: an employee can translate for two others, and a chain of such intermediaries is allowed. The company wants every pair of employees to be able to communicate, directly or indirectly.

The company may teach an employee a language they do not already know. Each such lesson costs 11. Find the minimum number of lessons needed to make communication possible between every pair of employees. An employee does not need to learn a language twice.

Input

The first line contains n,mn,m. The next nn lines each contain kik_i and kik_i distinct language indices known by employee ii.

Output

Print the minimum total cost.

Subtasks

  • Subtask 1 (20 points): 2≤n,m≤202\le n,m\le20; 0≤ki≤m0\le k_i\le m; the languages listed for an employee are distinct and belong to [1,m][1,m].
  • Subtask 2 (30 points): 2≤n,m≤602\le n,m\le60; 0≤ki≤m0\le k_i\le m; the languages listed for an employee are distinct and belong to [1,m][1,m].
  • Subtask 3 (50 points): 2≤n,m≤1002\le n,m\le100; 0≤ki≤m0\le k_i\le m; the languages listed for an employee are distinct and belong to [1,m][1,m].

Examples

Input

2 2
1 2
0

Output

1

Explanation

Employee 1 knows language 2; employee 2 knows none. Teaching language 2 to employee 2 costs exactly 1.