
typealias Graph = MutableList<MutableList<Int>>
fun create_empty_graph(n:Int):Graph{
    return MutableList(n) {_ -> mutableListOf<Int>()}
}
fun main(args:Array<String>) {
    val (n,m) = readLine()!!.split(" ").map(String::toInt)
    var g = create_empty_graph(n)
    for (_i in 0 until m) {
        var (x,y,_) = readLine()!!.split(" ").map(String::toInt)
        x--
        y--
        g[x].add(y)
        g[y].add(x)
    }

    var used = MutableList(n) {_ -> false}
    var cnt = 0
    for (i in 0 until n) {
        if(used[i]) continue
        var stack = mutableListOf<Int>()
        cnt++
        used[i] = true
        stack.add(i)
        while(!stack.isEmpty()){
            val v = stack.lastOrNull()!!
            stack.removeAt(stack.size-1)
            for(to in g[v]) {
                if(!used[to]) {
                    used[to] = true
                    stack.add(to)
                }
            }
        }
    }

    println(cnt)
}
