open Printf open Scanf
open Array

module UnionFind = struct
  let init n = Array.make n (-1)
  let is_root i a = a.(i) < 0
  let rec root_destructive x a =
    if a.(x) < 0 then x
    else (a.(x) <- root_destructive a.(x) a; a.(x))
  let size_destructive i a = let r = root_destructive i a in -a.(r)
  let same_destructive x y a = root_destructive x a = root_destructive y a
  let connect_destructive x y a =
    let p,q = root_destructive x a,root_destructive y a
    in if p = q then () else (
      let p,q = if a.(p) > a.(q) then q,p else p,q
      in
      a.(p) <- a.(p) + a.(q); a.(q) <- p)
end module UF = UnionFind

let () = scanf " %d %d" @@ fun n m ->
  let uf = UF.init n in
  let a = init m (fun _ -> scanf " %d %d %d" @@ fun x y z ->
    UF.connect_destructive (x-1) (y-1) uf;
  ) in
  init n (fun i ->
    if UF.is_root i uf then 1 else 0
  )
  |> fold_left (+) 0
  |> print_int
