let rec find x uf =
  if uf.(x) < 0 then
    x
  else
    let x' = find uf.(x) uf in
    uf.(x) <- x';
    x'

let unite x y uf =
  let x, y = find x uf, find y uf in
  if x <> y then
    if uf.(x) < uf.(y) then begin
      uf.(x) <- uf.(x) + uf.(y);
      uf.(y) <- x
    end else begin
      uf.(y) <- uf.(x) + uf.(y);
      uf.(x) <- y
    end

module S = Set.Make(struct type t = int let compare = (-) end)
  
let () =
  Scanf.scanf "%d %d" @@ fun n m ->
  let uf = Array.make n (-1) in
  for i = 1 to m do Scanf.scanf " %d %d %d" @@ fun x y _ -> unite (x-1) (y-1) uf done;
  Array.init n (fun i -> find i uf)
  |> Array.fold_left (fun s x -> S.add x s) S.empty
  |> S.cardinal |> Printf.printf "%d\n"

