class UnionFind:

    def __init__(self, max_size):

        self.parent = [i for i in range(max_size+1)]

        self.depth = [0 for _ in range(max_size+1)]

        self.cnt = [1 for i in range(max_size+1)]

    def find(self, x):

        if self.parent[x]==x:

            return x

        else:

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

            return self.parent[x]

    

    def unite(self,x,y):

        x = self.find(x)

        y = self.find(y)

        if x==y:

            return

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

            self.parent[x] = y

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

        else:

            self.parent[y] = x

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

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

                self.depth[x]+=1

    def same(self, x, y):

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

    def size(self,x):

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



n,m = list(map(int,input().split()))

utree = UnionFind(n+10)

for _ in range(m):

    x,y,z = list(map(int,input().split()))

    utree.unite(x,y)

s = {utree.find(i) for i in range(1,n+1)}

print((len(s)))
class UnionFind:

    def __init__(self, max_size):

        self.parent = [i for i in range(max_size+1)]

        self.depth = [0 for _ in range(max_size+1)]

        self.cnt = [1 for i in range(max_size+1)]

    def find(self, x):

        t = x

        while t!=self.parent[t]:

            t = self.parent[t]

        self.parent[x]=t

        return t

    

    def unite(self,x,y):

        x = self.find(x)

        y = self.find(y)

        if x==y:

            return

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

            self.parent[x] = y

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

        else:

            self.parent[y] = x

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

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

                self.depth[x]+=1

    def same(self, x, y):

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

    def size(self,x):

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



n,m = list(map(int,input().split()))

utree = UnionFind(n+10)

for _ in range(m):

    x,y,z = list(map(int,input().split()))

    utree.unite(x,y)

s = {utree.find(i) for i in range(1,n+1)}

print((len(s)))
class UnionFind:
    def __init__(self, max_size):
        self.parent = [i for i in range(max_size + 1)]
        self.depth = [0 for _ in range(max_size + 1)]
        self.cnt = [1 for i in range(max_size + 1)]

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

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        elif self.depth[x] < self.depth[y]:
            self.parent[x] = y
            self.cnt[y] += self.cnt[x]
        else:
            self.parent[y] = x
            self.cnt[x] += self.cnt[y]
            if self.depth[x] == self.depth[y]:
                self.depth[x] += 1

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

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


n, m = list(map(int, input().split()))
utree = UnionFind(n + 10)
for _ in range(m):
    x, y, z = list(map(int, input().split()))
    utree.unite(x, y)
s = {utree.find(i) for i in range(1, n + 1)}
print((len(s)))

class UnionFind:
    def __init__(self, max_size):
        self.parent = [i for i in range(max_size + 1)]
        self.depth = [0 for _ in range(max_size + 1)]
        self.cnt = [1 for i in range(max_size + 1)]

    def find(self, x):
        t = x
        while t != self.parent[t]:
            t = self.parent[t]
        self.parent[x] = t
        return t

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        elif self.depth[x] < self.depth[y]:
            self.parent[x] = y
            self.cnt[y] += self.cnt[x]
        else:
            self.parent[y] = x
            self.cnt[x] += self.cnt[y]
            if self.depth[x] == self.depth[y]:
                self.depth[x] += 1

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

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


n, m = list(map(int, input().split()))
utree = UnionFind(n + 10)
for _ in range(m):
    x, y, z = list(map(int, input().split()))
    utree.unite(x, y)
s = {utree.find(i) for i in range(1, n + 1)}
print((len(s)))

-        if self.parent[x] == x: -            return x -        else: -            self.parent[x] = self.find(self.parent[x]) -            return self.parent[x] +        t = x +        while t != self.parent[t]: +            t = self.parent[t] +        self.parent[x] = t +        return t