fun main(args: Array<String>) {
    val (n,m) = readLine()!!.split(" ").map { it.toInt() }
    val uft = UnionFindTree(n)
    (1..m).forEach {
        val (x,y,z) = readLine()!!.split(" ").map { it.toInt() }
        uft.unite(x-1,y-1)
    }
    println(uft.size())
}

class UnionFindTree(N:Int){
    private val parent = IntArray(N){ it }
    private val rank = IntArray(N){ 0 }
    private val size = IntArray(N){ 1 }
    private var numTree = N

    fun size() = numTree
    fun find(x:Int):Int = if(parent[x]==x)x else { parent[x] = find(parent[x]);parent[x] }
    fun same(x:Int,y:Int) = find(x)==find(y)
    fun sizeOf(x:Int) = size[find(x)]
    fun unite(x:Int,y:Int){
        val rx = find(x)
        val ry = find(y)
        if (rx==ry) return else numTree--

        if (rank[rx]<rank[ry]){
            parent[rx] = ry
            size[ry] += size[rx]
        } else {
            parent[ry] = rx
            size[rx] += size[ry]
            if( rank[rx]==rank[ry] ) rank[rx]++
        }
    }
}