import sys
sys.setrecursionlimit(10**9)

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

class Union_Find:
    def __init__(self,n):
        self.parent = [i for i in range(n)]
        self.rank = [1 for i in range(n)]
    
    def find(self,x):
        if self.parent[x] == x:
            return x
        else:
            return self.find(self.parent[x])
    
    def unite(self, x, y):
        px = self.find(x)
        py = self.find(y)
        if px == py:
            return
        else:
            if self.rank[px] == self.rank[py]:
                self.parent[py] = px
                self.rank[px] += 1
            elif self.rank[px] > self.rank[py]:
                self.parent[py] = px
            else:
                self.parent[px] = py
uftree = Union_Find(N+1)

for i in range(M):
    x, y, _ = map(int, input().split())
    uftree.unite(x, y)

result = 0
for i in range(1, N+1):
    if uftree.find(i) == i:
        result += 1

print(result)
 import sys sys sys.setrecursionlimit(10**9) sys.setrecursionlimit sys setrecursionlimit 10**9 10 9 N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M class Union_Find:
    def __init__(self,n):
        self.parent = [i for i in range(n)]
        self.rank = [1 for i in range(n)]
    
    def find(self,x):
        if self.parent[x] == x:
            return x
        else:
            return self.find(self.parent[x])
    
    def unite(self, x, y):
        px = self.find(x)
        py = self.find(y)
        if px == py:
            return
        else:
            if self.rank[px] == self.rank[py]:
                self.parent[py] = px
                self.rank[px] += 1
            elif self.rank[px] > self.rank[py]:
                self.parent[py] = px
            else:
                self.parent[px] = py Union_Find def __init__(self,n):
        self.parent = [i for i in range(n)]
        self.rank = [1 for i in range(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.parent = [i for i in range(n)] self.parent self parent [i for i in range(n)] 1 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 1 self.rank = [1 for i in range(n)] self.rank self rank [1 for i in range(n)] self self n n def find(self,x):
        if self.parent[x] == x:
            return x
        else:
            return self.find(self.parent[x])
    
     find if self.parent[x] == x:
            return x
        else:
            return self.find(self.parent[x])
    
     self.parent[x] == x self.parent[x] self.parent self parent x x return x x return self.find(self.parent[x]) self.find(self.parent[x]) self.find self find self.parent[x] self.parent self parent x self self x x def unite(self, x, y):
        px = self.find(x)
        py = self.find(y)
        if px == py:
            return
        else:
            if self.rank[px] == self.rank[py]:
                self.parent[py] = px
                self.rank[px] += 1
            elif self.rank[px] > self.rank[py]:
                self.parent[py] = px
            else:
                self.parent[px] = py unite px = self.find(x) px self.find(x) self.find self find x py = self.find(y) py self.find(y) self.find self find y if px == py:
            return
        else:
            if self.rank[px] == self.rank[py]:
                self.parent[py] = px
                self.rank[px] += 1
            elif self.rank[px] > self.rank[py]:
                self.parent[py] = px
            else:
                self.parent[px] = py px == py px py return if self.rank[px] == self.rank[py]:
                self.parent[py] = px
                self.rank[px] += 1
            elif self.rank[px] > self.rank[py]:
                self.parent[py] = px
            else:
                self.parent[px] = py self.rank[px] == self.rank[py] self.rank[px] self.rank self rank px self.rank[py] self.rank self rank py self.parent[py] = px self.parent[py] self.parent self parent py px self.rank[px] += 1 self.rank[px] self.rank self rank px 1 elif self.rank[px] > self.rank[py]:
                self.parent[py] = px
             self.rank[px] > self.rank[py] self.rank[px] self.rank self rank px self.rank[py] self.rank self rank py self.parent[py] = px self.parent[py] self.parent self parent py px self.parent[px] = py self.parent[px] self.parent self parent px py self self x x y y uftree = Union_Find(N+1) uftree Union_Find(N+1) Union_Find N+1 N 1 for i in range(M):
    x, y, _ = map(int, input().split())
    uftree.unite(x, y) i range(M) range M x, y, _ = map(int, input().split()) x map(int, input().split()) map int input().split() ().split () input split y _ uftree.unite(x, y) uftree.unite uftree unite x y result = 0 result 0 for i in range(1, N+1):
    if uftree.find(i) == i:
        result += 1 i range(1, N+1) range 1 N+1 N 1 if uftree.find(i) == i:
        result += 1 uftree.find(i) == i uftree.find(i) uftree.find uftree find i i result += 1 result 1 print(result) print result class Union_Find:
    def __init__(self,n):
        self.parent = [i for i in range(n)]
        self.rank = [1 for i in range(n)]
    
    def find(self,x):
        if self.parent[x] == x:
            return x
        else:
            return self.find(self.parent[x])
    
    def unite(self, x, y):
        px = self.find(x)
        py = self.find(y)
        if px == py:
            return
        else:
            if self.rank[px] == self.rank[py]:
                self.parent[py] = px
                self.rank[px] += 1
            elif self.rank[px] > self.rank[py]:
                self.parent[py] = px
            else:
                self.parent[px] = py class Union_Find:
    def __init__(self,n):
        self.parent = [i for i in range(n)]
        self.rank = [1 for i in range(n)]
    
    def find(self,x):
        if self.parent[x] == x:
            return x
        else:
            return self.find(self.parent[x])
    
    def unite(self, x, y):
        px = self.find(x)
        py = self.find(y)
        if px == py:
            return
        else:
            if self.rank[px] == self.rank[py]:
                self.parent[py] = px
                self.rank[px] += 1
            elif self.rank[px] > self.rank[py]:
                self.parent[py] = px
            else:
                self.parent[px] = py Union_Find uftree = Union_Find(N+1) Union_Find(N+1) uftree y, _ = map(int, input().split()) map(int, input().split()) y result += 1 1 result x, y, _ = map(int, input().split()) map(int, input().split()) x _ = map(int, input().split()) map(int, input().split()) _ M = map(int, input().split()) map(int, input().split()) M result = 0 0 result N, M = map(int, input().split()) map(int, input().split()) N
import sys
sys.setrecursionlimit(10**9)

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

class Union_Find:
    def __init__(self,n):
        self.parent = [i for i in range(n)]
        self.rank = [1 for i in range(n)]
    
    def find(self,x):
        if self.parent[x] == x:
            return x
        else:
            return self.find(self.parent[x])
    
    def unite(self, x, y):
        px = self.find(x)
        py = self.find(y)
        if px == py:
            return
        else:
            if self.rank[px] == self.rank[py]:
                self.parent[py] = px
                self.rank[px] += 1
            elif self.rank[px] > self.rank[py]:
                self.parent[py] = px
            else:
                self.parent[px] = py
uftree = Union_Find(N+1)

for i in range(M):
    x, y, _ = map(int, input().split())
    uftree.unite(x, y)

result = 0
for i in range(1, N+1):
    if uftree.find(i) == i:
        result += 1

print(result)

