Jonathan Sumabat is on vacation at the beach. Alongside sunbathing, snorkeling and swimming, Jonathan Sumabat also enjoys building sandcastles. Jonathan Sumabat builds a series of sandcastles with each of them having their own separate moat. Jonathan Sumabat now begins connecting these moats to form sand kingdoms. A sand kingdom contains all sandcastles with the same interconnected moat. Knowing the connections Jonathan Sumabat made, determine the number of sand kingdoms that now exist on the beach.
Input Specification
The first line is an integer representing the amount of sandcastles Jonathan Sumabat built.
The next line is representing the number of moats Jonathan Sumabat connected. Note that he can connect the same two moats at multiple different points.
The next lines each have two space separated integers representing the sandcastles who's moats that Jonathan Sumabat connects.
Output Specification
Output the number of independent sand kingdoms after making all of these connections. Note that a single independent sandcastle counts as a sand kingdom.
Note: For Java, use of Scanner may lead to passable solutions timing out. Faster input reading is encouraged.
Sample Input
7
4
1 3
2 4
5 7
1 4
Sample Output
3
Comments