#include d[100010],i; r(x){ i=d[x]<0?x:(d[x]=r(d[x])); } main(n,m,a,b,c){ scanf("%d%d",&n,&m); for(i=n;i--;)d[i]=-1; for(;m--;){ scanf("%d%d%d",&a,&b,&c); a=r(a-1);b=r(b-1); if(a-b)d[a]+=d[b],d[b]=a,--n; } i=!printf("%d\n",n); }