class UnionTree:

	# 節の数
	def __init__(self, N):
		self.__par = [i for i in range(N)]
		self.__rank = [0] * N

	# 根
	def root(self, x):
		if(self.__par[x] == x):
			return x
		else:
			self.__par[x] = self.root(self.__par[x])
			return self.__par[x]

	# 結合
	def unite(self, x, y):
		rx = self.root(x)
		ry = self.root(y)
		if(rx == ry):
			return

		if(self.__rank[rx] < self.__rank[ry]):
			self.__par[rx] = ry
		else:
			self.__par[ry] = rx
			if(self.__rank[rx] == self.__rank[ry]):
				self.__rank[rx] += 1

	# 一致
	def same(self, x, y):
		rx = self.root(x)
		ry = self.root(y)
		if(rx == ry):
			return True
		
		
# N枚のカードとルール
N, M = map(int, input().split())

# UnionTree Class
union_tree = UnionTree(N)

# ルールの適応
for i in range(M):
	# 結合
	a, b, x = map(int, input().split())
	union_tree.unite(a-1, b-1)

# 個数のみ数える
cnt = set()

for i in range(N):
	cnt.add(union_tree.root(i))

print(len(cnt)) class UnionTree:

	# 節の数
	def __init__(self, N):
		self.__par = [i for i in range(N)]
		self.__rank = [0] * N

	# 根
	def root(self, x):
		if(self.__par[x] == x):
			return x
		else:
			self.__par[x] = self.root(self.__par[x])
			return self.__par[x]

	# 結合
	def unite(self, x, y):
		rx = self.root(x)
		ry = self.root(y)
		if(rx == ry):
			return

		if(self.__rank[rx] < self.__rank[ry]):
			self.__par[rx] = ry
		else:
			self.__par[ry] = rx
			if(self.__rank[rx] == self.__rank[ry]):
				self.__rank[rx] += 1

	# 一致
	def same(self, x, y):
		rx = self.root(x)
		ry = self.root(y)
		if(rx == ry):
			return True
		
		
# N枚のカードとルール UnionTree def __init__(self, N):
		self.__par = [i for i in range(N)]
		self.__rank = [0] * N

	# 根
	 __init__ i for i in range(N) for i in range(N) i range(N) range N for i in range(N) i self.__par = [i for i in range(N)] self.__par self __par [i for i in range(N)] self.__rank = [0] * N self.__rank self __rank [0] * N [0] 0 N self self N N def root(self, x):
		if(self.__par[x] == x):
			return x
		else:
			self.__par[x] = self.root(self.__par[x])
			return self.__par[x]

	# 結合
	 root if(self.__par[x] == x):
			return x
		else:
			self.__par[x] = self.root(self.__par[x])
			return self.__par[x]

	# 結合
	 self.__par[x] == x self.__par[x] self.__par self __par x x return x x self.__par[x] = self.root(self.__par[x]) self.__par[x] self.__par self __par x self.root(self.__par[x]) self.root self root self.__par[x] self.__par self __par x return self.__par[x] self.__par[x] self.__par self __par x self self x x def unite(self, x, y):
		rx = self.root(x)
		ry = self.root(y)
		if(rx == ry):
			return

		if(self.__rank[rx] < self.__rank[ry]):
			self.__par[rx] = ry
		else:
			self.__par[ry] = rx
			if(self.__rank[rx] == self.__rank[ry]):
				self.__rank[rx] += 1

	# 一致
	 unite rx = self.root(x) rx self.root(x) self.root self root x ry = self.root(y) ry self.root(y) self.root self root y if(rx == ry):
			return

		 rx == ry rx ry return if(self.__rank[rx] < self.__rank[ry]):
			self.__par[rx] = ry
		else:
			self.__par[ry] = rx
			if(self.__rank[rx] == self.__rank[ry]):
				self.__rank[rx] += 1

	# 一致
	 self.__rank[rx] < self.__rank[ry] self.__rank[rx] self.__rank self __rank rx self.__rank[ry] self.__rank self __rank ry self.__par[rx] = ry self.__par[rx] self.__par self __par rx ry self.__par[ry] = rx self.__par[ry] self.__par self __par ry rx if(self.__rank[rx] == self.__rank[ry]):
				self.__rank[rx] += 1

	# 一致
	 self.__rank[rx] == self.__rank[ry] self.__rank[rx] self.__rank self __rank rx self.__rank[ry] self.__rank self __rank ry self.__rank[rx] += 1 self.__rank[rx] self.__rank self __rank rx 1 self self x x y y def same(self, x, y):
		rx = self.root(x)
		ry = self.root(y)
		if(rx == ry):
			return True
		
		
# N枚のカードとルール same rx = self.root(x) rx self.root(x) self.root self root x ry = self.root(y) ry self.root(y) self.root self root y if(rx == ry):
			return True
		
		
# N枚のカードとルール rx == ry rx ry return True True self self x x y y N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M union_tree = UnionTree(N) union_tree UnionTree(N) UnionTree N for i in range(M):
	# 結合
	a, b, x = map(int, input().split())
	union_tree.unite(a-1, b-1)

# 個数のみ数える i range(M) range M a, b, x = map(int, input().split()) a map(int, input().split()) map int input().split() ().split () input split b x union_tree.unite(a-1, b-1) union_tree.unite union_tree unite a-1 a 1 b-1 b 1 cnt = set() cnt set() set for i in range(N):
	cnt.add(union_tree.root(i)) i range(N) range N cnt.add(union_tree.root(i)) cnt.add cnt add union_tree.root(i) union_tree.root union_tree root i print(len(cnt)) print len(cnt) len cnt b, x = map(int, input().split()) map(int, input().split()) b x = map(int, input().split()) map(int, input().split()) x cnt = set() set() cnt class UnionTree:

	# 節の数
	def __init__(self, N):
		self.__par = [i for i in range(N)]
		self.__rank = [0] * N

	# 根
	def root(self, x):
		if(self.__par[x] == x):
			return x
		else:
			self.__par[x] = self.root(self.__par[x])
			return self.__par[x]

	# 結合
	def unite(self, x, y):
		rx = self.root(x)
		ry = self.root(y)
		if(rx == ry):
			return

		if(self.__rank[rx] < self.__rank[ry]):
			self.__par[rx] = ry
		else:
			self.__par[ry] = rx
			if(self.__rank[rx] == self.__rank[ry]):
				self.__rank[rx] += 1

	# 一致
	def same(self, x, y):
		rx = self.root(x)
		ry = self.root(y)
		if(rx == ry):
			return True
		
		
# N枚のカードとルール class UnionTree:

	# 節の数
	def __init__(self, N):
		self.__par = [i for i in range(N)]
		self.__rank = [0] * N

	# 根
	def root(self, x):
		if(self.__par[x] == x):
			return x
		else:
			self.__par[x] = self.root(self.__par[x])
			return self.__par[x]

	# 結合
	def unite(self, x, y):
		rx = self.root(x)
		ry = self.root(y)
		if(rx == ry):
			return

		if(self.__rank[rx] < self.__rank[ry]):
			self.__par[rx] = ry
		else:
			self.__par[ry] = rx
			if(self.__rank[rx] == self.__rank[ry]):
				self.__rank[rx] += 1

	# 一致
	def same(self, x, y):
		rx = self.root(x)
		ry = self.root(y)
		if(rx == ry):
			return True
		
		
# N枚のカードとルール UnionTree a, b, x = map(int, input().split()) map(int, input().split()) a union_tree = UnionTree(N) UnionTree(N) union_tree N, M = map(int, input().split()) map(int, input().split()) N M = map(int, input().split()) map(int, input().split()) M
class UnionTree:

	# 節の数
	def __init__(self, N):
		self.__par = [i for i in range(N)]
		self.__rank = [0] * N

	# 根
	def root(self, x):
		if(self.__par[x] == x):
			return x
		else:
			self.__par[x] = self.root(self.__par[x])
			return self.__par[x]

	# 結合
	def unite(self, x, y):
		rx = self.root(x)
		ry = self.root(y)
		if(rx == ry):
			return

		if(self.__rank[rx] < self.__rank[ry]):
			self.__par[rx] = ry
		else:
			self.__par[ry] = rx
			if(self.__rank[rx] == self.__rank[ry]):
				self.__rank[rx] += 1

	# 一致
	def same(self, x, y):
		rx = self.root(x)
		ry = self.root(y)
		if(rx == ry):
			return True
		
		
# N枚のカードとルール
N, M = map(int, input().split())

# UnionTree Class
union_tree = UnionTree(N)

# ルールの適応
for i in range(M):
	# 結合
	a, b, x = map(int, input().split())
	union_tree.unite(a-1, b-1)

# 個数のみ数える
cnt = set()

for i in range(N):
	cnt.add(union_tree.root(i))

print(len(cnt))