class UnionFind:
    def __init__(self, n):
        self.p = [i for i in range(n)]
        self.components = n

    def root(self, x):
        if self.p[x] == x:
            return x
        else:
            self.p[x] = self.root(self.p[x])
            return self.p[x]
    
    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x != y:
            self.p[x] = y
            self.components -= 1
    
    def same(self, x,y):
        return (self.root(x) == self.root(y))
N, M = map(int,input().split())

UF = UnionFind(N)

for _ in range(M):
    X, Y, Z = map(int,input().split())
    X, Y = X-1, Y-1
    UF.unite(X,Y)

print(UF.components) class UnionFind:
    def __init__(self, n):
        self.p = [i for i in range(n)]
        self.components = n

    def root(self, x):
        if self.p[x] == x:
            return x
        else:
            self.p[x] = self.root(self.p[x])
            return self.p[x]
    
    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x != y:
            self.p[x] = y
            self.components -= 1
    
    def same(self, x,y):
        return (self.root(x) == self.root(y)) UnionFind def __init__(self, n):
        self.p = [i for i in range(n)]
        self.components = 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.p = [i for i in range(n)] self.p self p [i for i in range(n)] self.components = n self.components self components n self self n n def root(self, x):
        if self.p[x] == x:
            return x
        else:
            self.p[x] = self.root(self.p[x])
            return self.p[x]
    
     root if self.p[x] == x:
            return x
        else:
            self.p[x] = self.root(self.p[x])
            return self.p[x]
    
     self.p[x] == x self.p[x] self.p self p x x return x x self.p[x] = self.root(self.p[x]) self.p[x] self.p self p x self.root(self.p[x]) self.root self root self.p[x] self.p self p x return self.p[x] self.p[x] self.p self p x self self x x def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x != y:
            self.p[x] = y
            self.components -= 1
    
     unite x, y = self.root(x), self.root(y) x self.root(x) self.root self root x y self.root(y) self.root self root y if x != y:
            self.p[x] = y
            self.components -= 1
    
     x != y x y self.p[x] = y self.p[x] self.p self p x y self.components -= 1 self.components self components 1 self self x x y y def same(self, x,y):
        return (self.root(x) == self.root(y)) same return (self.root(x) == self.root(y)) self.root(x) == self.root(y) self.root(x) self.root self root x self.root(y) self.root self root y 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 UF = UnionFind(N) UF UnionFind(N) UnionFind N for _ in range(M):
    X, Y, Z = map(int,input().split())
    X, Y = X-1, Y-1
    UF.unite(X,Y) _ range(M) range M X, Y, Z = map(int,input().split()) X map(int,input().split()) map int input().split() ().split () input split Y Z X, Y = X-1, Y-1 X X-1 X 1 Y Y-1 Y 1 UF.unite(X,Y) UF.unite UF unite X Y print(UF.components) print UF.components UF components UF = UnionFind(N) UnionFind(N) UF Y, Z = map(int,input().split()) map(int,input().split()) Y X, Y, Z = map(int,input().split()) map(int,input().split()) X Z = map(int,input().split()) map(int,input().split()) Z X, Y = X-1, Y-1 X-1 X M = map(int,input().split()) map(int,input().split()) M Y = X-1, Y-1 Y-1 Y N, M = map(int,input().split()) map(int,input().split()) N class UnionFind:
    def __init__(self, n):
        self.p = [i for i in range(n)]
        self.components = n

    def root(self, x):
        if self.p[x] == x:
            return x
        else:
            self.p[x] = self.root(self.p[x])
            return self.p[x]
    
    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x != y:
            self.p[x] = y
            self.components -= 1
    
    def same(self, x,y):
        return (self.root(x) == self.root(y)) class UnionFind:
    def __init__(self, n):
        self.p = [i for i in range(n)]
        self.components = n

    def root(self, x):
        if self.p[x] == x:
            return x
        else:
            self.p[x] = self.root(self.p[x])
            return self.p[x]
    
    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x != y:
            self.p[x] = y
            self.components -= 1
    
    def same(self, x,y):
        return (self.root(x) == self.root(y)) UnionFind
class UnionFind:
    def __init__(self, n):
        self.p = [i for i in range(n)]
        self.components = n

    def root(self, x):
        if self.p[x] == x:
            return x
        else:
            self.p[x] = self.root(self.p[x])
            return self.p[x]
    
    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x != y:
            self.p[x] = y
            self.components -= 1
    
    def same(self, x,y):
        return (self.root(x) == self.root(y))
N, M = map(int,input().split())

UF = UnionFind(N)

for _ in range(M):
    X, Y, Z = map(int,input().split())
    X, Y = X-1, Y-1
    UF.unite(X,Y)

print(UF.components)