# frozen_string_literal: true

n, m = gets.split.map(&:to_i)

uf = [*0..n]
rank = Array.new(n + 1) { 0 }

def root(uf, i)
  uf[i] == i ? i : (uf[i] = root uf, uf[i])
end

m.times do
  x, y = gets.split.map(&:to_i)
  x = root uf, x
  y = root uf, y

  next if x == y

  if rank[x] > rank[y]
    uf[y] = x
  else
    uf[x] = y
    rank[y] += 1 if rank[x] == rank[y]
  end
end

puts 1.upto(n).count { |i| root(uf, i) == i }