import java.util.*

fun main(args: Array<String>) {
    val (cardCount, inputCount) = readLine()!!.split(" ").map { it.toInt() }
    val map = mutableMapOf<Int, MutableMap<Int, Boolean>>()
    val list = mutableListOf<Card>()
    for(i in 1..cardCount) {
        list.add(Card(i-1))
    }
    for(i in 1..inputCount) {
        val (a, b) = readLine()!!.split(" ").take(2).map { it.toInt() - 1 }
        listOf(a,b).forEach {
            if(!map.containsKey(it)) {
                map[it] = mutableMapOf()
            }
        }
        map[a]!![b] = true
        map[b]!![a] = true
    }
    var found = 0
    for( card in list) {
        if(card.flag) {
            continue
        }
        found++
        card.flag = true
        val queue = LinkedList<Card>()
        queue.add(card)
        while (queue.isNotEmpty()) {
            val target = queue.pop()
            map[target.id]?.let {
                it.keys.forEach {
                    if(!list[it].flag) {
                        list[it].flag = true
                        queue.add(list[it])
                    }
                }
            }
        }
    }
    println(found + list.count { !it.flag })
}

class Card(val id:Int) {
    var flag = false
}
