#include <iostream>

using namespace std;
#define ll long long;
int N,M,A[100005];
int ref(int i)
  {if(A[i]==i)return i;
   return A[i]=ref(A[i]);
      
  }
int main()
{
cin>>N>>M;
int x,y,z,t1,t2;

for(int i=0;i<N+1;i++)
   {A[i]=i;
   }
int b=N;
while(M--)
  {cin>>x>>y>>z;
    t1=ref(x);  t2=ref(y);
    if(t1==t2) continue;
    A[t1]=t2;
    b--;
  }
  cout<<b;
   
}
