#K72442. Connect All Players

    ID: 33754 Type: Default 1000ms 256MiB

Connect All Players

Connect All Players

You are given N players and M connections between them. Each connection links two players. Your task is to determine the minimum number of additional connections required so that every player can reach every other player via some series of connections.

In graph theory terms, the players form the vertices of a graph and the connections form an undirected edge between vertices. The problem asks for the minimum number of edges needed so that the graph becomes connected. Recall that if there are k connected components in a graph, then at least \(k - 1\) additional edges are needed to connect all components.

Input/Output Format: The input is read from stdin and the output should be written to stdout.

inputFormat

The first line contains two integers N and M where N is the number of players and M is the number of connections.

The next M lines each contain two integers u and v indicating that there is a connection between players u and v.

outputFormat

Output a single integer: the minimum number of additional connections required to connect all players.

## sample
5 3
1 2
2 3
4 5
1