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

def find(x):
    if parents[x] < 0: # 負なら根
        return x
    else:
        parents[x] = find(parents[x])
        return parents[x]
    
#xとyの属する集合の併合
def unite(x,y):
    x = find(x) # x,yは根の番号にする。
    y = find(y)
    
    if x == y:
        return False
    else:
        if parents[x] > parents[y]: # sizeの大きいほうがx
            x,y = y,x
        parents[x] += parents[y]
        parents[y] = x
        return True

parents=[-1]*n

for i in range(m):
    x,y,z=map(int,input().split())
    unite(x-1,y-1)

ans=0
for i in range(n):
    if parents[i]<0:
        ans+=1
print(ans) n,m=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m def find(x):
    if parents[x] < 0: # 負なら根
        return x
    else:
        parents[x] = find(parents[x])
        return parents[x]
    
#xとyの属する集合の併合 find if parents[x] < 0: # 負なら根
        return x
    else:
        parents[x] = find(parents[x])
        return parents[x]
    
#xとyの属する集合の併合 parents[x] < 0 parents[x] parents x 0 return x x parents[x] = find(parents[x]) parents[x] parents x find(parents[x]) find parents[x] parents x return parents[x] parents[x] parents x x x def unite(x,y):
    x = find(x) # x,yは根の番号にする。
    y = find(y)
    
    if x == y:
        return False
    else:
        if parents[x] > parents[y]: # sizeの大きいほうがx
            x,y = y,x
        parents[x] += parents[y]
        parents[y] = x
        return True unite x = find(x) x find(x) find x y = find(y) y find(y) find y if x == y:
        return False
    else:
        if parents[x] > parents[y]: # sizeの大きいほうがx
            x,y = y,x
        parents[x] += parents[y]
        parents[y] = x
        return True x == y x y return False False if parents[x] > parents[y]: # sizeの大きいほうがx
            x,y = y,x
         parents[x] > parents[y] parents[x] parents x parents[y] parents y x,y = y,x x y y x parents[x] += parents[y] parents[x] parents x parents[y] parents y parents[y] = x parents[y] parents y x return True True x x y y parents=[-1]*n parents [-1]*n [-1] -1 n for i in range(m):
    x,y,z=map(int,input().split())
    unite(x-1,y-1) i 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 unite(x-1,y-1) unite x-1 x 1 y-1 y 1 ans=0 ans 0 for i in range(n):
    if parents[i]<0:
        ans+=1 i range(n) range n if parents[i]<0:
        ans+=1 parents[i]<0 parents[i] parents i 0 ans+=1 ans 1 print(ans) print ans ans=0 0 ans m=map(int,input().split()) map(int,input().split()) m x,y,z=map(int,input().split()) map(int,input().split()) x def unite(x,y):
    x = find(x) # x,yは根の番号にする。
    y = find(y)
    
    if x == y:
        return False
    else:
        if parents[x] > parents[y]: # sizeの大きいほうがx
            x,y = y,x
        parents[x] += parents[y]
        parents[y] = x
        return True def unite(x,y):
    x = find(x) # x,yは根の番号にする。
    y = find(y)
    
    if x == y:
        return False
    else:
        if parents[x] > parents[y]: # sizeの大きいほうがx
            x,y = y,x
        parents[x] += parents[y]
        parents[y] = x
        return True unite def find(x):
    if parents[x] < 0: # 負なら根
        return x
    else:
        parents[x] = find(parents[x])
        return parents[x]
    
#xとyの属する集合の併合 def find(x):
    if parents[x] < 0: # 負なら根
        return x
    else:
        parents[x] = find(parents[x])
        return parents[x]
    
#xとyの属する集合の併合 find parents=[-1]*n [-1]*n parents y,z=map(int,input().split()) map(int,input().split()) y z=map(int,input().split()) map(int,input().split()) z n,m=map(int,input().split()) map(int,input().split()) n ans+=1 1 ans
n,m=map(int,input().split())

def find(x):
    if parents[x] < 0: # 負なら根
        return x
    else:
        parents[x] = find(parents[x])
        return parents[x]
    
#xとyの属する集合の併合
def unite(x,y):
    x = find(x) # x,yは根の番号にする。
    y = find(y)
    
    if x == y:
        return False
    else:
        if parents[x] > parents[y]: # sizeの大きいほうがx
            x,y = y,x
        parents[x] += parents[y]
        parents[y] = x
        return True

parents=[-1]*n

for i in range(m):
    x,y,z=map(int,input().split())
    unite(x-1,y-1)

ans=0
for i in range(n):
    if parents[i]<0:
        ans+=1
print(ans)