module UnionFind

implicit none
integer,allocatable,dimension(:)::par
!parentより

contains

recursive function root(x) result(res)
integer :: x,res
if(par(x) /= x)par(x) = root(par(x))
res = par(x)
end function

subroutine unite(x,y)
integer :: x,y
x = root(x)
y = root(y)
if(x /= y) par(x) = y
end subroutine

subroutine UFinit(N)
integer :: N
integer::i
  allocate(par(N))
  do i = 1, N
    par(i) = i
  end do
end subroutine
end module UnionFind
program main
  use UnionFind
  implicit none
  integer::N,M
  integer::X,Y,Z
  integer::ANS=0
  integer::i
  read*,N,M
  call UFinit(N)
  do i=1,M
    read*,X,Y,Z
    call unite(X,Y)
  end do
  do i=1,N
    if(par(i)==i)ANS=ANS+1
  end do
  print"(i0)",ANS
end program main