import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n, m = sc.nextInt()

    val par = new Array[Int](n)
    init(par)

    for (i <- 0 until m) {
      val x, y, z = sc.nextInt()
      unite(par, x-1, y-1)
    }

    var ans = 0

    for (i <- par.indices) {
      if (isParent(par, i)) ans += 1
    }

    println(ans)
  }

  def isParent(par: Array[Int], x: Int): Boolean = {
    par(x) == x
  }

  def init(par: Array[Int]): Unit = {
    for (i <- par.indices) {
      par(i) = i
    }
  }


  @scala.annotation.tailrec
  def root(par: Array[Int], x: Int): Int = {
    if (par(x) == x) {
      x
    } else {
      par(x) = x
      root(par, par(x))
    }
  }

  def same(par: Array[Int], x: Int, y: Int): Boolean = {
    root(par, x) == root(par, y)
  }

  def unite(par: Array[Int], x: Int, y: Int): Unit = {
    if (!(root(par, x) == root(par, y)))
      par(root(par, x)) = root(par, y)
  }
}
