eolymp
bolt
Try our new interface for solving problems

Roads

In Ukraine, as you know, a lot of problems. One of them --- the road. The newly elected president of Ukraine decided to do road construction. His goal --- to build some additional amount of roads between cities so that you can drive from any city of Ukraine in any (possibly through other cities, not necessarily directly). Naturally, any additional roads should be built as possible. We assume that all the roads in Ukraine bilateral (and already available, and those that will be built), that is, it may move in both directions. Note that between the two cities may be somewhat expensive. In addition, there may be roads connecting the city to itself. \InputFile The first line contains two natural numbers $n$ and $m\:(1 \le n, m \le 10000)$ --- number of cities and the number of existing roads. The following $m$ lines contain two integers $a_i$ and $b_i\:(1 \le a_i, b_i \le n)$ --- the numbers of cities connected to an existing road. \OutputFile Print the minimum number of roads to be constructed, to exist a path from any city to any. \includegraphics{https://static.e-olymp.com/content/7d/7db37796051b373cae229dbd30afbc78215ae345.gif}
Time limit 1 second
Memory limit 128 MiB
Input example #1
7 5
1 3
2 3
3 2
2 4
6 7
Output example #1
2
Source Crimea-2010