lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

N = lines[0][0]
M = lines[0][1]

access = []
for i in 1..N do
  access[i-1] = []
end

for i in 1..M do
  from = lines[i][0]
  to = lines[i][1]
  access[from-1].push(to)
  access[to-1].push(from)
end

visited = []
cluster = []
for i in 1..N do
  visited[i-1] = false
  cluster[i-1] = 0
end

num_cluster = 0
for k in 1..N do
  if visited[k-1] == false then
    num_cluster += 1
    cluster[k-1] = num_cluster
    target = [k-1]
    while target != [] do
      i = target.pop
      access[i-1].each do |j|
        if visited[j-1] == false then
          cluster[j-1] = num_cluster
          target.push(j)
          visited[j-1] = true
        end
      end
    end
  end
end
    
puts num_cluster