import java.util.*

class UnionFind(n: Long) {
    val size = n.toInt()

    private val parent: Array<Long>
    private val cardinality: Array<Long>

    init {
        parent = Array(size) { -1L }
        cardinality = Array(size) { 1L }
    }

    fun find(x: Long): Long {
        return if (parent[x.toInt()] == -1L) {
            x
        } else {
            parent[x.toInt()] = find(parent[x.toInt()])
            parent[x.toInt()]
        }
    }

    fun unite(x: Long, y: Long): Boolean {
        val u = find(x).toInt()
        val v = find(y).toInt()
        if (u == v) {
            return false
        }

        val newSize = cardinality[v] + cardinality[u]

        if (cardinality[u] < cardinality[v]) {
            parent[u] = v.toLong()
            cardinality[v] = newSize
        } else {
            parent[v] = u.toLong()
            cardinality[u] = newSize
        }

        return true
    }

    fun same(x: Long, y: Long): Boolean {
        return find(x) == find(y)
    }

    fun getCardinalityOf(x: Long): Long {
        return cardinality[find(x).toInt()]
    }
}

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)

    var N: Long
    N = sc.nextLong()
    var M: Long
    M = sc.nextLong()
    val X = Array((M).toInt()){0L}
    val Y = Array((M).toInt()){0L}
    val Z = Array((M).toInt()){0L}
    for (i in 0 until M) {
        X[(i).toInt()] = sc.nextLong()
        Y[(i).toInt()] = sc.nextLong()
        Z[(i).toInt()] = sc.nextLong()
    }
    solve(N, M, X, Y, Z)
}

fun solve(N: Long, M: Long, X: Array<Long>, Y: Array<Long>, Z: Array<Long>) {
    var res = N

    val uf = UnionFind(N + 1)

    for (i in X.indices) {
        if (uf.unite(X[i], Y[i])) {
            --res
        }
    }
    println(res)
}

