(* https://atcoder.jp/contests/atc001/tasks/unionfind_a *)
open Printf
open Scanf

class unionfind size =
  object(self)
    val mutable forest = [|(0,0)|]
    initializer begin
      forest <- Array.init size (fun x -> (x,1))
    end
    method forest () = begin
      forest
    end
    method print_forest () = begin
      let _ = Array.iter (fun x -> Printf.printf "(%d,%d);" (fst x) (snd x)) forest in
      print_newline()
    end
    method group_count () = begin
      let count = ref 0 in
      let _ = Array.iteri (fun i x -> if i = fst x then count := !count + 1) forest in
      !count
    end
    method find i = begin
      let (index, size) = forest.(i) in
      if (i = index) then (i, size)
      else
        let (nxt_index, nxt_size) = self#find index in
        forest.(i) <- (nxt_index, nxt_size);
        (nxt_index, nxt_size)
    end

    method union i j = begin
      let (x, x_size) = self#find i in
      let (y, y_size) = self#find j in

      if (x = y) then ()
      else
        let () = forest.(x) <- (y, x_size + y_size) in
        forest.(y) <- (y, x_size + y_size)
    end
  end

(*
let t = new unionfind 5;;
t#union 0 1;;
t#union 3 4;;
t#forest();;
t#find 0;;
*)

let (n,m) = sscanf (read_line ()) "%d %d" (fun a b -> (a,b))
let query = Array.make m (0,0,0);;
let () = 
for i = 0 to m-1 do
  query.(i) <- sscanf (read_line ()) "%d %d %d" (fun x y z-> (x-1,y-1,z))
done;;

let forest = new unionfind n;;
let () = Array.iter (fun t -> let (x,y,z) = t in forest#union x y) query;;
let () = print_int (forest#group_count ()) in print_newline();;