N, M = gets.split.map(&:to_i)
A = [*0..N]
ID = lambda{|i|
	return i == A[i] ? i : (A[i]=ID[A[i]])
}
c = N
$<.each{|ln|
	x, y, = ln.split.map(&:to_i)
	a, b = ID[x], ID[y]
	next if a == b
	A[a] = A[b] = [a, b].min
	c -= 1
}
p c
