def r;gets.split.map &:to_i;end
class UnionFind
  def initialize(n, &block)
    @par = Array.new(n,&:itself)
    @rank = Array.new(n,1)
    instance_eval(&block) if block_given?
  end

  def root(a)
    par = @par[a]
    a == par ? a : @par[a] = root(par)
  end

  def unite(a,b)
    a = root(a); b = root(b)
    return if a == b

    @rank[a] < @rank[b] ? @par[a] = b : @par[b] = a
    @rank[a] += 1 if @rank[a] == @rank[b]
  end

  def same(a,b)
    root(a) == root(b)
  end

  def roots
    @par.map{|a|root(a)}
  end
end

# sample AB126_E
N,M = r

UnionFind.new(N) do
  M.times do
    a,b = r; a-=1; b-=1;
    unite(a,b)
  end
  UF = roots
end

p UF.uniq.size