





import sys

from collections import deque, defaultdict

import copy

import bisect

input=sys.stdin.readline

sys.setrecursionlimit(10 ** 9)

import math



N, M = list(map(int, input().split()))

XYZ = []

for i in range(M):

	XYZ.append(list(map(int, input().split())))



renketu = [dict() for i in range(N)]

for i in range(N):

	renketu[i]["iro"] = -1

	renketu[i]["eda"] = []

for i in range(M):

	renketu[XYZ[i][0] - 1]["eda"].append([XYZ[i][0], XYZ[i][1]])

	renketu[XYZ[i][1] - 1]["eda"].append([XYZ[i][1], XYZ[i][0]])



num = 0

for i in range(N):

	if renketu[i]['iro'] == -1:

		num += 1

		stack = [i]

		# print(rest, num)

		renketu[i]['iro'] = num

		while len(stack) > 0:

			node = stack.pop()

			for edge in renketu[node]["eda"]:

				if renketu[edge[1] - 1]["iro"] == -1:

					renketu[edge[1] - 1]["iro"] = num

					stack.append(edge[1] - 1)



print(num)




import sys

def input():

	return sys.stdin.readline().strip()



N, M = list(map(int, input().split()))





class Union_Find():

	def __init__(self, n):

		self.union = [i for i in range(n)]

		self.level = [0 for i in range(n)]

		self.num = n



	def root(self, i, mode=0):

		keiro = [i]

		ans = i

		while ans != self.union[ans]:

			ans = self.union[ans]

			keiro.append(ans)

		if mode == 0:

			return ans

		else:

			return ans, keiro



	def unite(self, i, j):

		root_i, list_i = self.root(i, 1)

		root_j, list_j = self.root(j, 1)

		if root_i != root_j:

			self.num -= 1

			if self.level[root_i] < self.level[root_j]:

				self.level[root_j] = max(self.level[root_i] + 1, self.level[root_j])

				for node in list_i:

					self.union[node] = root_j

			else:

				self.level[root_i] = max(self.level[root_j] + 1, self.level[root_i])

				for node in list_j:

					self.union[node] = root_i



union = Union_Find(N)



for i in range(M):

	X, Y, Z = list(map(int, input().split()))

	union.unite(X - 1, Y - 1)



print((union.num))
import sys
from collections import deque, defaultdict
import copy
import bisect

input = sys.stdin.readline
sys.setrecursionlimit(10**9)
import math

N, M = list(map(int, input().split()))
XYZ = []
for i in range(M):
    XYZ.append(list(map(int, input().split())))
renketu = [dict() for i in range(N)]
for i in range(N):
    renketu[i]["iro"] = -1
    renketu[i]["eda"] = []
for i in range(M):
    renketu[XYZ[i][0] - 1]["eda"].append([XYZ[i][0], XYZ[i][1]])
    renketu[XYZ[i][1] - 1]["eda"].append([XYZ[i][1], XYZ[i][0]])
num = 0
for i in range(N):
    if renketu[i]["iro"] == -1:
        num += 1
        stack = [i]
        # print(rest, num)
        renketu[i]["iro"] = num
        while len(stack) > 0:
            node = stack.pop()
            for edge in renketu[node]["eda"]:
                if renketu[edge[1] - 1]["iro"] == -1:
                    renketu[edge[1] - 1]["iro"] = num
                    stack.append(edge[1] - 1)
print(num)

import sys


def input():
    return sys.stdin.readline().strip()


N, M = list(map(int, input().split()))


class Union_Find:
    def __init__(self, n):
        self.union = [i for i in range(n)]
        self.level = [0 for i in range(n)]
        self.num = n

    def root(self, i, mode=0):
        keiro = [i]
        ans = i
        while ans != self.union[ans]:
            ans = self.union[ans]
            keiro.append(ans)
        if mode == 0:
            return ans
        else:
            return ans, keiro

    def unite(self, i, j):
        root_i, list_i = self.root(i, 1)
        root_j, list_j = self.root(j, 1)
        if root_i != root_j:
            self.num -= 1
            if self.level[root_i] < self.level[root_j]:
                self.level[root_j] = max(self.level[root_i] + 1, self.level[root_j])
                for node in list_i:
                    self.union[node] = root_j
            else:
                self.level[root_i] = max(self.level[root_j] + 1, self.level[root_i])
                for node in list_j:
                    self.union[node] = root_i


union = Union_Find(N)
for i in range(M):
    X, Y, Z = list(map(int, input().split()))
    union.unite(X - 1, Y - 1)
print((union.num))

-from collections import deque, defaultdict -import copy -import bisect -input = sys.stdin.readline -sys.setrecursionlimit(10**9) -import math + +def input(): +    return sys.stdin.readline().strip() + -XYZ = [] + + +class Union_Find: +    def __init__(self, n): +        self.union = [i for i in range(n)] +        self.level = [0 for i in range(n)] +        self.num = n + +    def root(self, i, mode=0): +        keiro = [i] +        ans = i +        while ans != self.union[ans]: +            ans = self.union[ans] +            keiro.append(ans) +        if mode == 0: +            return ans +        else: +            return ans, keiro + +    def unite(self, i, j): +        root_i, list_i = self.root(i, 1) +        root_j, list_j = self.root(j, 1) +        if root_i != root_j: +            self.num -= 1 +            if self.level[root_i] < self.level[root_j]: +                self.level[root_j] = max(self.level[root_i] + 1, self.level[root_j]) +                for node in list_i: +                    self.union[node] = root_j +            else: +                self.level[root_i] = max(self.level[root_j] + 1, self.level[root_i]) +                for node in list_j: +                    self.union[node] = root_i + + +union = Union_Find(N) -    XYZ.append(list(map(int, input().split()))) -renketu = [dict() for i in range(N)] -for i in range(N): -    renketu[i]["iro"] = -1 -    renketu[i]["eda"] = [] -for i in range(M): -    renketu[XYZ[i][0] - 1]["eda"].append([XYZ[i][0], XYZ[i][1]]) -    renketu[XYZ[i][1] - 1]["eda"].append([XYZ[i][1], XYZ[i][0]]) -num = 0 -for i in range(N): -    if renketu[i]["iro"] == -1: -        num += 1 -        stack = [i] -        # print(rest, num) -        renketu[i]["iro"] = num -        while len(stack) > 0: -            node = stack.pop() -            for edge in renketu[node]["eda"]: -                if renketu[edge[1] - 1]["iro"] == -1: -                    renketu[edge[1] - 1]["iro"] = num -                    stack.append(edge[1] - 1) -print(num) +    X, Y, Z = list(map(int, input().split())) +    union.unite(X - 1, Y - 1) +print((union.num))