# https://atcoder.jp/contests/abc126/tasks/abc126_e
class UnionFindWithType
  attr_reader :types
  def initialize(size)
    @rank = Array.new(size, 0)
    @parent = Array.new(size, &:itself)
    @types = size
  end

  def unite(id_x, id_y)
    x_parent = get_parent(id_x)
    y_parent = get_parent(id_y)
    return if x_parent == y_parent
    @types -= 1
    if @rank[x_parent] > @rank[y_parent]
      @parent[y_parent] = x_parent
    else
      @parent[x_parent] = y_parent
      @rank[y_parent] += 1 if @rank[x_parent] == @rank[y_parent]
    end
  end

  def get_parent(id_x)
    @parent[id_x] == id_x ? id_x : (@parent[id_x] = get_parent(@parent[id_x]))
  end
end

N, M = gets.split.map(&:to_i)
uf = UnionFindWithType.new(N)
M.times do
  uf.unite(*gets.split.take(2).map { |s| s.to_i - 1 })
end
p uf.types