#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"r=lambda x:x*(u[x]<0)or r(u[x])\n"
"i=lambda:map(int,input().split()[:2])\n"
"n,m=i()\n"
"u=[-1]*-~n\n"
"while m:\n"
" x,y=sorted(map(r,i()));m-=1\n"
" if x!=y:u[x]+=u[y];u[y]=x\n"
"print(sum(i<0for i in u)-1)\n"
"\"";
  system(s);
  return 0;
}            