import java.util.Scanner

import scala.collection.mutable.ArrayBuffer


object Main {
  case class Edge(x: Int, y: Int, z: Long)
  
  def read() = {
    val sc = new Scanner(System.in)
    val n, m = sc.nextInt()
    //0-index化
    val edges = IndexedSeq.fill(m)(Edge(sc.nextInt() - 1, sc.nextInt() - 1, sc.nextInt()))

    (n, m, edges)
  }


  def solve2(n: Int, m: Int, edges: IndexedSeq[Edge]): Int = {
    var cnt = 0 // 連結成分数

    val nextList = IndexedSeq.fill(n)(ArrayBuffer.empty[Edge])
    for (edge <- edges) {
      val from = edge.x
      val to = edge.y
      nextList(from).append(edge)
      nextList(to).append(Edge(to, from, edge.z))
    }

    val visited = Array.fill(n)(false)
    for (i <- 0 until n) {
      if (!visited(i)) {
        visited(i) = true
        cnt += 1
        //BFS
        val open: java.util.Queue[Int] = new java.util.ArrayDeque[Int]()
        open.add(i)
        while (!open.isEmpty) {
          val current = open.remove()
          for (edge <- nextList(current)) {
            val next = edge.y
            if(!visited(next)) {
              open.add(next)
              visited(next) = true
            }
          }
        }

      }
    }
    cnt
  }

  def main(args: Array[String]): Unit = {
    val (n, m, edges) = read()
    println(solve2(n, m, edges))
  }
}
