class UnionFind:
    def __init__(self, N):
        self.root = [-1 for _ in range(N)]
        self.size = [1 for _ in range(N)]

    def find(self, x):
        while self.root[x] >= 0:
            x = self.root[x]
        return x

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.size[x] < self.size[y]:
            self.root[x] = y
            self.size[y] += self.size[x]
        else:
            self.root[y] = x
            self.size[x] += self.size[y]

N, M = [int(_) for _ in input().split()]
uf = UnionFind(N)

for i in range(M):
    X, Y, Z = [int(_) for _ in input().split()]
    uf.union(X-1, Y-1)

ans = set()
for i in range(N):
    ans.add(uf.find(i))
print(len(ans)) class UnionFind:
    def __init__(self, N):
        self.root = [-1 for _ in range(N)]
        self.size = [1 for _ in range(N)]

    def find(self, x):
        while self.root[x] >= 0:
            x = self.root[x]
        return x

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.size[x] < self.size[y]:
            self.root[x] = y
            self.size[y] += self.size[x]
        else:
            self.root[y] = x
            self.size[x] += self.size[y] UnionFind def __init__(self, N):
        self.root = [-1 for _ in range(N)]
        self.size = [1 for _ in range(N)]

     __init__ -1 for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) -1 self.root = [-1 for _ in range(N)] self.root self root [-1 for _ in range(N)] 1 for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) 1 self.size = [1 for _ in range(N)] self.size self size [1 for _ in range(N)] self self N N def find(self, x):
        while self.root[x] >= 0:
            x = self.root[x]
        return x

     find while self.root[x] >= 0:
            x = self.root[x]
         self.root[x] >= 0 self.root[x] self.root self root x 0 x = self.root[x] x self.root[x] self.root self root x return x x self self x x def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.size[x] < self.size[y]:
            self.root[x] = y
            self.size[y] += self.size[x]
        else:
            self.root[y] = x
            self.size[x] += self.size[y] union x = self.find(x) x self.find(x) self.find self find x y = self.find(y) y self.find(y) self.find self find y if x == y:
            return
         x == y x y return if self.size[x] < self.size[y]:
            self.root[x] = y
            self.size[y] += self.size[x]
        else:
            self.root[y] = x
            self.size[x] += self.size[y] self.size[x] < self.size[y] self.size[x] self.size self size x self.size[y] self.size self size y self.root[x] = y self.root[x] self.root self root x y self.size[y] += self.size[x] self.size[y] self.size self size y self.size[x] self.size self size x self.root[y] = x self.root[y] self.root self root y x self.size[x] += self.size[y] self.size[x] self.size self size x self.size[y] self.size self size y self self x x y y int(_) for _ in input().split() for _ in input().split() _ input().split() ().split () input split for _ in input().split() int(_) int _ N, M = [int(_) for _ in input().split()] N [int(_) for _ in input().split()] M uf = UnionFind(N) uf UnionFind(N) UnionFind N for i in range(M):
    X, Y, Z = [int(_) for _ in input().split()]
    uf.union(X-1, Y-1) i range(M) range M int(_) for _ in input().split() for _ in input().split() _ input().split() ().split () input split for _ in input().split() int(_) int _ X, Y, Z = [int(_) for _ in input().split()] X [int(_) for _ in input().split()] Y Z uf.union(X-1, Y-1) uf.union uf union X-1 X 1 Y-1 Y 1 ans = set() ans set() set for i in range(N):
    ans.add(uf.find(i)) i range(N) range N ans.add(uf.find(i)) ans.add ans add uf.find(i) uf.find uf find i print(len(ans)) print len(ans) len ans N, M = [int(_) for _ in input().split()] [int(_) for _ in input().split()] N Y, Z = [int(_) for _ in input().split()] [int(_) for _ in input().split()] Y Z = [int(_) for _ in input().split()] [int(_) for _ in input().split()] Z M = [int(_) for _ in input().split()] [int(_) for _ in input().split()] M ans = set() set() ans X, Y, Z = [int(_) for _ in input().split()] [int(_) for _ in input().split()] X class UnionFind:
    def __init__(self, N):
        self.root = [-1 for _ in range(N)]
        self.size = [1 for _ in range(N)]

    def find(self, x):
        while self.root[x] >= 0:
            x = self.root[x]
        return x

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.size[x] < self.size[y]:
            self.root[x] = y
            self.size[y] += self.size[x]
        else:
            self.root[y] = x
            self.size[x] += self.size[y] class UnionFind:
    def __init__(self, N):
        self.root = [-1 for _ in range(N)]
        self.size = [1 for _ in range(N)]

    def find(self, x):
        while self.root[x] >= 0:
            x = self.root[x]
        return x

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.size[x] < self.size[y]:
            self.root[x] = y
            self.size[y] += self.size[x]
        else:
            self.root[y] = x
            self.size[x] += self.size[y] UnionFind uf = UnionFind(N) UnionFind(N) uf
class UnionFind:
    def __init__(self, N):
        self.root = [-1 for _ in range(N)]
        self.size = [1 for _ in range(N)]

    def find(self, x):
        while self.root[x] >= 0:
            x = self.root[x]
        return x

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.size[x] < self.size[y]:
            self.root[x] = y
            self.size[y] += self.size[x]
        else:
            self.root[y] = x
            self.size[x] += self.size[y]

N, M = [int(_) for _ in input().split()]
uf = UnionFind(N)

for i in range(M):
    X, Y, Z = [int(_) for _ in input().split()]
    uf.union(X-1, Y-1)

ans = set()
for i in range(N):
    ans.add(uf.find(i))
print(len(ans))
