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

edges = [list(map(int, input().split())) for _ in range(M)]



class UnionFind:

    def __init__(self, n):

        self.par = list(range(n))

        self.rank = [0] * n

        

    def find(self, x):

        if self.par[x] == x:

            return x

        else:

            self.par[x] = self.find(self.par[x])

            return self.par[x]

        

    def unite(self, x, y):

        x = self.find(x)

        y = self.find(y)

        if x == y:

            return

        

        if self.rank[x] == self.rank[y]:

            self.rank[x] += 1

        elif self.rank[x] < self.rank[y]:

            x, y = y, x

            

        self.par[y] = x

    

    def get_par(self):

        return self.par



t = UnionFind(N)

for u, v, _ in edges:

    t.unite(u - 1, v - 1)



print((len(set(t.find(x) for x in range(N)))))



class UnionFind:

    def __init__(self, n):

        self.par = list(range(n))

        self.rank = [0] * n

        self.size = [1] * n



    def find(self, x):

        if self.par[x] == x:

            return x

        else:

            self.par[x] = self.find(self.par[x])

            return self.par[x]



    def unite(self, x, y):

        x = self.find(x)

        y = self.find(y)



        if x == y:

            return



        if self.rank[x] == self.rank[y]:

            self.rank[x] += 1

        elif self.rank[x] < self.rank[y]:

            x, y = y, x



        self.par[y] = x

        self.size[x] += self.size[y]



    def is_same(self, x, y):

        return self.find(x) == self.find(y)



    def get_size(self, x):

        return self.size[self.find(x)]





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

X = [list(map(int, input().split())) for _ in range(M)]



tree = UnionFind(N)

for x, y, z in X:

    tree.unite(x - 1, y - 1)



# Update

for x in range(N):

    tree.find(x)



print((len(set(tree.par))))

N, M = list(map(int, input().split()))
edges = [list(map(int, input().split())) for _ in range(M)]


class UnionFind:
    def __init__(self, n):
        self.par = list(range(n))
        self.rank = [0] * n

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1
        elif self.rank[x] < self.rank[y]:
            x, y = y, x
        self.par[y] = x

    def get_par(self):
        return self.par


t = UnionFind(N)
for u, v, _ in edges:
    t.unite(u - 1, v - 1)
print((len(set(t.find(x) for x in range(N)))))

class UnionFind:
    def __init__(self, n):
        self.par = list(range(n))
        self.rank = [0] * n
        self.size = [1] * n

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1
        elif self.rank[x] < self.rank[y]:
            x, y = y, x
        self.par[y] = x
        self.size[x] += self.size[y]

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def get_size(self, x):
        return self.size[self.find(x)]


N, M = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(M)]
tree = UnionFind(N)
for x, y, z in X:
    tree.unite(x - 1, y - 1)
# Update
for x in range(N):
    tree.find(x)
print((len(set(tree.par))))

-N, M = list(map(int, input().split())) -edges = [list(map(int, input().split())) for _ in range(M)] - - +        self.size = [1] * n +        self.size[x] += self.size[y] -    def get_par(self): -        return self.par +    def is_same(self, x, y): +        return self.find(x) == self.find(y) + +    def get_size(self, x): +        return self.size[self.find(x)] -t = UnionFind(N) -for u, v, _ in edges: -    t.unite(u - 1, v - 1) -print((len(set(t.find(x) for x in range(N))))) +N, M = list(map(int, input().split())) +X = [list(map(int, input().split())) for _ in range(M)] +tree = UnionFind(N) +for x, y, z in X: +    tree.unite(x - 1, y - 1) +# Update +for x in range(N): +    tree.find(x) +print((len(set(tree.par))))