import java.util.*

val MAX_N = 100002
var par = Array(MAX_N){0}
var rank = Array(MAX_N){0}

fun init() {
    for (i in 0 until MAX_N) {
        par[i] = i
        rank[i] = 0
    }
}

fun find(a: Int): Int{
    if (par[a] == a){
        return a
    } else {
        par[a] = find(par[a])
        return par[a]
    }
}

fun unite(a: Int, b: Int) {
    val ta = find(a)
    val tb = find(b)
    if(ta == tb) return

    if(rank[ta] < rank[tb]){
        par[ta] = tb
    }else{
        par[tb] = ta
        if(rank[ta] == rank[tb]) rank[ta]++
    }
}

fun same(a: Int, b: Int): Boolean {
    return find(a) == find(b)
}

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val N = sc.nextInt()
    val M = sc.nextInt()
    val rem = (1..N).toMutableSet()

    init()

    repeat(M) {
        val x = sc.nextInt()
        val y = sc.nextInt()
        val z = sc.nextInt()
        unite(x, y)
        rem.remove(x)
        rem.remove(y)
    }

    val set = mutableSetOf<Int>()
    for (i in 1..N) {
        set.add(find(i))
    }
    println(set.size)
}