fun visit(node: Int, visited: Array<Boolean>, edges: Array<MutableList<Int>>) {
    if (visited[node]) return
    visited[node] = true
    edges[node].forEach { x -> visit(x, visited, edges) }
}

fun main(args: Array<String>) {
    val (N, M) = readLine()!!.split(" ").map(String::toInt)
    val edges = Array(N){mutableListOf<Int>()}
    for (i in 0..M-1){
        val (x, y, z) = readLine()!!.split(" ").map(String::toInt)
        edges[x - 1].add(y - 1)
        edges[y - 1].add(x - 1)
    }

    var cnt = 0
    val visited = Array(N) { false }
    for (i in 0..N-1) {
        if (!visited[i]) {
            visit(i, visited, edges)
            cnt++
        }
    }
    println(cnt)
}