Problem:
Score : 300 points

Problem Statement

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.

Sample Input 1

3 1
1 2

Sample Output 1

1

Initially, there are three cities, and there is a road between City 1 and City 2.

Snuke can achieve the goal by building one new road, for example, between City 1 and City 3.
After that,

We can travel between 1 and 2 directly.

We can travel between 1 and 3 directly.

We can travel between 2 and 3 by following both roads (2 - 1 - 3).

Solution in C++ (GCC 9.2.1) (judge verdict: Wrong Answer)

#include<bits/stdc++.h>
#include<queue>
using namespace std;

#define what_is(x) cout << #x << " is " << x << endl;
#define PI acos(-1)
#define hell 1000000007
#define HELL 998244353
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fix(n) cout << fixed << setprecision(n)
#define mset(a,n) memset(a,n,sizeof a)
#define rep(i,a,b) for (__typeof((b)) i=(a);i<(b);i++)
#define repp(i,a,b,p) for(__typeof((b)) i=(a);i<(b);i+=p)
#define ren(i,a,b) for(__typeof((a)) i=(a);i>=(b);i--)
#define renn(i,a,b,p) for(__typeof((a) i=(a);i>=(b);i-=p)
#define ADD(a,b,c) ((a)%c+(b)%c)%c
#define SUB(a,b,c) ((a)%c-(b)%c+c)%c
#define MUL(a,b,c) (((a)%c)*((b)%c))%c
#define lbd lower_bound
#define ubd upper_bound
#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define all(v) (v).begin(), (v).end()
#define sz(x) (ll)x.size()
// #define out(n) cout<<n<<" "
#define outl(n) cout<<n<<endl
#define bug(n) {outl(n);return;}
#define pii pair<int,int>
#define lim 9223372036854775806
#define ninf -9223372036854775802
#define M 998244353  
#define eps 1e-9
#define MAX 2
#define N 2
#define db(a) for(auto it:a) {cout<<it<<" ";}cout<<endl;
ll prime[MAX];
ll fact[MAX];

const long long INF64 = 1e18;
ll vpow(ll a, ll b, ll p) {
    if (b == 0)
        return 1;
    if (b == 1)
        return a;
    ll temp = vpow(a, b / 2, p);
    temp *= temp;
    temp %= p;
    if (b % 2 == 0)
        return temp;
    temp = temp * a;
    temp %= p;
    return temp;
}

ll gcd(ll a, ll b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}


ll inverseMod(ll a, ll b, ll p) {
    if (b == 0)
        return 1;
    ll temp = vpow(b, p - 2, p);
    ll ans = temp * a;
    ans %= p;
    return ans;
}
void sieve()
{
    prime[0] = prime[1] = 1;
    for (ll i = 2; i < MAX; i++) {
        if (prime[i] == 0) {
            for (int j = i * 2; j < MAX; j += i) {
                if (prime[j] == 0) {
                    prime[j] = i;
                }
            }
            prime[i] = i;
        }
    }
}


void factorial() {
    fact[0] = 1;
    fact[1] = 1;
    rep(i, 2, MAX) {
        fact[i] = (fact[i - 1] * i);
         fact[i]%=M;
    }
}
void dfs(vector<ll> adj[],ll u,vector<bool> &vis){
    vis[u]=true;
    for(auto ch:adj[u]){
        if(!vis[ch])
            dfs(adj,ch,vis);
    }
}
void solve(ll test){
    ll n,m;
    cin>>n>>m;
    vll adj[n];
    rep(i,0,m){
        ll u,v;
        cin>>u>>v;
        u--;v--;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    ll ans=0;
    vector<bool> vis(n,false);
    rep(i,0,n){
        if(!vis[i]){
            ans++;
            dfs(adj,i,vis);
        }
    }
    cout<<ans<<endl;
}
int main() {
    io;
    // sieve();
    factorial();
#ifndef ONLINE_JUDGE
    freopen("input1.txt", "r", stdin);
    // freopen("output1.txt","w",stdout);
#endif

    ll t = 1;
    //cin >> t;
    fix(12);
    rep(q, 1, t + 1) {
        // cout<<"Test case : "<<q<<endl;
        solve(q);
        //solve2();
    }
    return 0;

}