Skip to content
UPEEC

Connected Components

Medium#graphs#dfs#union-find· solved by 0 · time limit 2.0 s

An undirected graph has nn vertices (numbered 1…n1 \dots n) and mm edges. How many connected components does it have?

Input

nn and mm, then mm lines u v.

Output

The number of components.

Constraints

1≤n≤1051 \le n \le 10^5, 0≤m≤2×1050 \le m \le 2 \times 10^5

Sample 1

Input

5 3
1 2
2 3
4 5

Output

2

Sample 2

Input

3 0

Output

3

Sign in or join free to run and submit your solution.