class Union {
  var rank: [Int] = []
  var parent: [Int] = []
  init(_ n: Int) {
    rank = .init(repeating: 0, count: n)
    parent = (0..<n).map { $0 }
  }
  func root(_ x: Int) -> Int {
    if parent[x] == x {
      return x
    }
    parent[x] = root(parent[x])
    return parent[x]
  }
  func merge(_ x: Int, _ y: Int) {
    let px = root(x)
    let py = root(y)
    if px == py {
      return
    }
    if rank[px] < rank[py] {
      parent[px] = py
      rank[py] += rank[px]
    } else if rank[px] > rank[py] {
      parent[py] = px
      rank[px] += rank[py]
    } else {
      parent[py] = px
      rank[px] += rank[py]
    }
  }
  func uniqueCount() -> Int {
    return Set(parent.map { root($0) } ).count
  }
}
 
let input = readLine()!.split(separator: " ").map { Int($0)! }
let N = input[0]
let M = input[1]

let union = Union(N)
for _ in 0..<M {
  let s = readLine()!.split(separator: " ").map { Int($0)! }
  let x = s[0] - 1
  let y = s[1] - 1
  union.merge(x, y)
}

print(union.uniqueCount())
