#include<bits/stdc++.h>

    ///--------------------------------------------------------------------------------
    #define     T()                 ll t;    cin>>t;        while(t--)
    #define        ll                  long long
    #define        vi                     vector<ll>
    #define     pii                 pair<ll,ll>
    #define     vpair                 vector< pii >
    #define     fast                 ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    #define     repp(i,a,n)         for(ll i= a ; i < n ; ++i)
    #define     rep(i,n)            for(ll i= 0 ; i < n ; ++i)
    #define     p_b                     push_back
    #define     p_f                 push_front
    #define     pop_b                 pop_back()
    #define     pop_f                 pop_front()
    #define     m_p                 make_pair
    #define      sumv(v)              accumulate(v.begin(),v.endd(),0);
    #define     sortv(v)             sort(v.begin(),v.endd())
    #define     sort_dec(v)         sort(v.begin(),v.endd(),greater<ll>() )
    #define     l_b(v,l)               lower_bound (v.begin(), v.endd(), l)
    #define     u_b(v,l)               upper_bound (v.begin(), v.endd(), l)
    #define     pq                     priority_queue
    #define     ff                     first
    #define     ss                     second
    #define     len                 length()
    #define     all(v)              v.begin(),v.endd()
    #define     mset(a,b)           memset(a,b,sizeof(a));

    ///==========INPUT=============///
    #define     sc(a)           cin>>a;
    #define     sc2(a,b)        cin>>a>>b;
    #define     sc3(a,b,c)      cin>>a>>b>>c;
    #define     sc4(a,b,c,d)    cin>>a>>b>>c>>d;
    ///==========PRINTING=============///
    #define     prarr(arr)      rep(i,sizeof(arr)/sizeof(ll)) cout<<arr[i]<<" "; nl
    #define     prvec(v)        rep(i,v.size()) cout<<v[i]<<" "; nl
    #define     pr(x)           cout<<x<<"\n";
    #define     pr2(x, y)       cout<<x<<" "<<y<<"\n";
    #define     pr3(x, y, z)    cout<<x<<" "<<y<<" "<<z<<"\n";

    ///==========DEBUGGING=============///
    #define     debug(a)             cout<<"*"<<a<<enddl;
    #define     debug2(a,b)         cout<<"$"<<a<<" "<<b<<enddl;
    #define     debug3(a,b,c)         cout<<"$"<<a<<" "<<b<<" "<<c<<enddl;
    #define     bug                 cout<<"#"<<enddl;
    #define     nl                     cout<<'\n';
    #define     enddl                '\n'

    ///==========CONSTANTS=============///
    #define     max6     1000005
    #define     max5     100004
    #define     max4     10003
    #define     mod       1000000007
    #define     inf      1e9
    ll powermod(ll _a,ll _b,ll _m)    {ll _r=1;while(_b){if(_b%2==1)_r=(_r*_a)%_m;_b/=2;_a=(_a*_a)%_m;}return _r;}

    using namespace std;
    ll par[max5];
    ll parent(ll a)
    {
        while(par[a]!=a)
        {
            par[a]=par[par[a]];
            a=par[a];

        }
        return a;
    }
    void join(ll a,ll b)
    {
        ll p1=parent(a);
        ll p2=parent(b);
        par[p2]=p1;
    }

    int main()
    {
        fast
        ll n,m;
        sc2(n,m)
        ll a,b,c;
        rep(i,n)
        par[i]=i;
        rep(i,m)
        {
            sc3(a,b,c)
            join(a,b);
        }
        set<ll> s;
        rep(i,n)
        s.insert(parent(i));
        cout<<s.size();
    }


Measured memory_bytes: 5760