There are N cities numbered 1 through N, and M bidirectional roads numbered 1 through M. Road i connects City A_i and City B_i.

Snuke can perform the following operation zero or more times:

* Choose two distinct cities that are not directly connected by a road, and build a new road between the two cities.



After he finishes the operations, it must be possible to travel from any city to any other cities by following roads (possibly multiple times).

What is the minimum number of roads he must build to achieve the goal?

Constraints

* 2 \leq N \leq 100,000
* 1 \leq M \leq 100,000
* 1 \leq A_i < B_i \leq N
* No two roads connect the same pair of cities.
* All values in input are integers.

Input

Input is given from Standard Input in the following format:


N M
A_1 B_1
:
A_M B_M


Output

Print the answer.

Example

Input

3 1
1 2


Output

1
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	static class Node {
		int id;
		int group;
		Set<Integer> conns;

		Node(int id) {
			this.id = id;
			this.group = -1;
			this.conns = new HashSet<>();
		}
	}

	int N, M;
	Node[] nodes;

	Main(BufferedReader in) throws IOException {
		String[] tokens = in.readLine().split(" ");
		N = Integer.parseInt(tokens[0]);
		M = Integer.parseInt(tokens[1]);
		nodes = new Node[N];
		for (int i = 0; i < N; ++i) {
			nodes[i] = new Node(i);
		}
		for (int i = 0; i < M; ++i) {
			tokens = in.readLine().split(" ");
			int A = Integer.parseInt(tokens[0]) - 1;
			int B = Integer.parseInt(tokens[1]) - 1;
			nodes[A].conns.add(B);
			nodes[B].conns.add(A);
		}
	}

	void mark(int current, int group, int parent) {
		if (nodes[current].group >= 0) {
			return;
		}
		nodes[current].group = group;
		for (Integer next : nodes[current].conns) {
			if (!next.equals(parent)) {
				mark(next, group, current);
			}
		}
	}

	void calc() {
		int group = 0;
		for (int i = 0; i < N; ++i) {
			if (nodes[i].group < 0) {
				mark(i, group, -1);
				++group;
			}
		}
		System.out.println((group - 1));
	}

	void showResult() {
	}
}
