require "pp"

class Main
  def run()
    @n, @m = gets.split(" ").map(&:to_i)
    @graph = {}
    @m.times do |i|
      x, y = gets.split(" ").map(&:to_i)

      @graph[x] ||= []
      @graph[y] ||= []
      @graph[x] << y
      @graph[y] << x
    end

    (1..@n).each do |i|
      @graph[i] ||= []
    end

    @res = {}
    (1..@n).each do |i|
      dfs(i, i)
    end

    puts @res.values.uniq.count
  end

  def dfs(i, mark)
    unless @res[i].nil?
      return
    end

    @res[i] = mark
    @graph[i].each do |x|
      dfs(x, mark)
    end
  end
end

main = Main.new()
main.run()
