Problem:
Score : 500 points

Problem Statement

There are N cards placed face down in a row. On each card, an integer 1 or 2 is written.

Let A_i be the integer written on the i-th card.

Your objective is to guess A_1, A_2, ..., A_N correctly.

You know the following facts:

For each i = 1, 2, ..., M, the value A_{X_i} + A_{Y_i} + Z_i is an even number.

You are a magician and can use the following magic any number of times:

Magic: Choose one card and know the integer A_i written on it. The cost of using this magic is 1.

What is the minimum cost required to determine all of A_1, A_2, ..., A_N?

It is guaranteed that there is no contradiction in given input.

Constraints

All values in input are integers.

2 \leq N \leq 10^5

1 \leq M \leq 10^5

1 \leq X_i < Y_i \leq N

1 \leq Z_i \leq 100

The pairs (X_i, Y_i) are distinct.

There is no contradiction in input. (That is, there exist integers A_1, A_2, ..., A_N that satisfy the conditions.)

Input

Input is given from Standard Input in the following format:

N M
X_1 Y_1 Z_1
X_2 Y_2 Z_2
\vdots
X_M Y_M Z_M

Output

Print the minimum total cost required to determine all of A_1, A_2, ..., A_N.

Sample Input 1

3 1
1 2 1

Sample Output 1

2

You can determine all of A_1, A_2, A_3 by using the magic for the first and third cards.

Sample Input 2

6 5
1 2 1
2 3 2
1 3 3
4 5 4
5 6 5

Sample Output 2

2

Sample Input 3

100000 1
1 100000 100

Sample Output 3

99999

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

/*
ID: hepic
PROG: sabotage
LANG: C++11
*/
#include <bits/stdc++.h>

#define FOR(i, a, b) for(auto i=a; i<=b; ++i)
#define REP(i, a, b) for(auto i=a; i<b; ++i)
#define FORI(i, a, b) for(auto i=a; i!=b+1-2*(a>b); i+=1-2*(a>b))
#define REPI(i, a, b) for(auto i=a-(a>b); i!=b-(a>b); i+=1-2*(a>b))
#define ALL(v) v.begin(),v.end()
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define eb(a, b) emplace_back(a, b)
#define fir first
#define sec second
#define what_is(x) cout<<#x<<" is "<<x<<endl;
#define type(x) typeid(x).name()
#define ms(arr, val) memset(arr, val, sizeof(arr))
#define min3(a,b,c) min(min(a,b),c)
#define max3(a,b,c) max(max(a,b),c)
#define PI acos(-1)
#define open_read freopen("disrupt.in", "r", stdin)
#define open_write freopen("disrupt.out", "w", stdout)

using namespace std;

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef pair<double, double> PDD;
typedef pair<int, int> PII;
typedef pair<int, PII> PIPII;
typedef pair<PII, PII> PPIIPII;
typedef pair<LL, LL> PLL;
typedef pair<ULL, ULL> PUU;
typedef pair<LL, PLL> PLPLL;
typedef pair<PLL, PLL> PPLLPLL;
typedef pair<int, LL> PIL;
typedef pair<LL, int> PLI;


template<typename T, typename T1>
ostream& operator << (ostream &out, pair<T, T1> obj) {
    out << "(" << obj.first << ", " << obj.second << ")";
    return out;
}


template<typename T, typename T1>
ostream& operator << (ostream &out, map<T, T1> cont) {
    typename map<T, T1>::const_iterator itr = cont.begin();
    typename map<T, T1>::const_iterator ends = cont.end();

    for(; itr != ends; ++itr) {
        out << *itr << " ";
    }

    out<<endl;
    return out;
}


template<typename T>
ostream& operator << (ostream &out, set<T> cont) {
    typename set<T>::const_iterator itr = cont.begin();
    typename set<T>::const_iterator ends = cont.end();
    
    for(; itr != ends; ++itr) {
        out << *itr << " ";
    }

    out << endl;
    return out;
}


template<typename T>
ostream& operator << (ostream &out, multiset<T> cont) {
    typename multiset<T>::const_iterator itr = cont.begin();
    typename multiset<T>::const_iterator ends = cont.end();

    for (; itr != ends; ++itr) {
        out << *itr << " ";
    }

    out << endl;
    return out;
}


template<typename T, template<typename ELEM, typename ALLOC=allocator<ELEM>> class CONT>
ostream& operator << (ostream &out, CONT<T> cont) {
    typename CONT<T>::const_iterator itr = cont.begin();
    typename CONT<T>::const_iterator ends = cont.end();

    for (; itr != ends; ++itr) {
        out << *itr << " ";
    }

    out << endl;
    return out;
}


template<typename T, unsigned int N, typename CTy, typename CTr>
typename enable_if<!is_same<T, char>::value, basic_ostream<CTy, CTr> &>::type
operator << (basic_ostream<CTy, CTr> &out, const T (&arr)[N]) {
    REP (i, 0, N) {
        out << arr[i] << " ";
    }

    out << endl;
    return out;
}


template<typename T>
T GCD(T a, T b) {
    T min_v = min(a, b);
    T max_v = max(a, b);

    while (min_v) {
        T temp = max_v % min_v;
        max_v = min_v;
        min_v = temp;
    }

    return max_v;
}


template<typename T>
T LCM(T a, T b) {
    return (a*b) / gcd(a, b);
}


template<typename T>
T fastExpPow(T base, T exp, T mod) {
    T res = 1;

    while (exp) {
        if (exp&1) {
            res *= base;
            res %= mod;
        }

        exp >>= 1;
        base *= base;
        base %= mod;
    }

    return res % mod;
}

/*#################################################################################################################
###################################################################################################################
###################################################################################################################
#################################################################################################################*/

#define SIZE 100010

int N, M, U, V, Z, result;
bool visited[SIZE];
vector<int> graph[SIZE];

void dfs(int node) {
    visited[node] = true;
    
    for (auto connNode: graph[node]) {
        if (!visited[connNode]) {
            dfs(connNode);
        }
    }
}


int main() {
    scanf("%d%d", &N, &M);

    REP (i, 0, M) {
        scanf("%d%d%d", &U, &V, &Z);
        graph[U].pb(V);
        graph[V].pb(U);
    }

    FOR (i, 1, N) {
        if (!visited[i]) {
            ++result;
            dfs(i);
        }
    }
    
    printf("%d\n", result);
    return 0;
}