#P6153. Counting Unique Items

    ID: 19373 Type: Default 1000ms 256MiB

Counting Unique Items

Counting Unique Items

Zbw has n items numbered from 1 to n. He will give you m conditions, each containing two integers x and y. Each condition indicates that the x-th and the y-th items are the same. Since zbw is in a hurry, he guarantees that every condition given is useful, meaning that no condition can be derived from the previous conditions.

Your task is to determine the number of different items after considering all the conditions.

Note: Because each condition is useful, every condition effectively merges two previously distinct groups. Thus, if there are no conditions, the answer is n and each condition reduces the total count by 1.

The answer can be computed as:

\[ \text{answer} = n-m \]

inputFormat

The first line contains two space-separated integers n and m.

Each of the following m lines contains two space-separated integers x and y representing a condition that the x-th item and the y-th item are the same.

outputFormat

Output a single integer representing the number of different items.

sample

5 0
5