PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#DSU0000007. Thi công đường phố (Road Construction)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Thi công đường phố (Road Construction)

Road Construction

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

A city has nn intersections and mm bidirectional roads. Find the minimum number of roads to add so that every intersection is reachable from every other intersection.

Input

The first line contains two integers n,mn,m. Each of the next mm lines contains two integers a,ba,b, describing a road between intersections aa and bb. Intersections are numbered from 11 to nn.

Output

Print the minimum number of additional roads required.

Subtasks

  • Subtask 1 (20 points): 1≤n≤1501\le n\le 150; 0≤m≤1700\le m\le 170; 1≤a,b≤n1\le a,b\le n; a≠ba\ne b; no repeated edges.
  • Subtask 2 (30 points): 1≤n≤100001\le n\le 10000; 0≤m≤60000\le m\le 6000; 1≤a,b≤n1\le a,b\le n; a≠ba\ne b; no repeated edges.
  • Subtask 3 (50 points): 1≤n≤1000001\le n\le 100000; 0≤m≤1000000\le m\le 100000; 1≤a,b≤n1\le a,b\le n; a≠ba\ne b; no repeated edges.

Examples

Input

4 2
1 2
3 4

Output

1

Explanation

The intersections form two groups: {1,2}\{1,2\} and {3,4}\{3,4\}. One new road can connect them.