from collections import defaultdict, deque
dic = defaultdict(list)

N, M = map(int, input().split())
hint= [-1]*N

for _ in range(M):
    x, y, z = map(int, input().split())
    dic[x].append(y)
    dic[y].append(x)
    hint[x-1]=0
    hint[y-1]=0
    
count = 0
ans=0
for i in range(N):
    if hint[i]==0:
        count+=1
        hint[i]=count
        queue = deque()
        for j in dic[i+1]:
            if hint[j-1]==0:
                queue.append(j)
                hint[j-1]=count
        while queue:
            x = queue.popleft()
            for k in dic[x]:
                if hint[k-1]==0:
                    hint[k-1]=count
                    queue.append(k)        
        continue
    elif hint[i]==-1:
        ans+=1
print(ans+count) from collections import defaultdict, deque dic = defaultdict(list) dic defaultdict(list) defaultdict list N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M hint= [-1]*N hint [-1]*N [-1] -1 N for _ in range(M):
    x, y, z = map(int, input().split())
    dic[x].append(y)
    dic[y].append(x)
    hint[x-1]=0
    hint[y-1]=0
     _ 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 dic[x].append(y) [x].append [x] dic x append y dic[y].append(x) [y].append [y] dic y append x hint[x-1]=0 hint[x-1] hint x-1 x 1 0 hint[y-1]=0 hint[y-1] hint y-1 y 1 0 count = 0 count 0 ans=0 ans 0 for i in range(N):
    if hint[i]==0:
        count+=1
        hint[i]=count
        queue = deque()
        for j in dic[i+1]:
            if hint[j-1]==0:
                queue.append(j)
                hint[j-1]=count
        while queue:
            x = queue.popleft()
            for k in dic[x]:
                if hint[k-1]==0:
                    hint[k-1]=count
                    queue.append(k)        
        continue
    elif hint[i]==-1:
        ans+=1 i range(N) range N if hint[i]==0:
        count+=1
        hint[i]=count
        queue = deque()
        for j in dic[i+1]:
            if hint[j-1]==0:
                queue.append(j)
                hint[j-1]=count
        while queue:
            x = queue.popleft()
            for k in dic[x]:
                if hint[k-1]==0:
                    hint[k-1]=count
                    queue.append(k)        
        continue
    elif hint[i]==-1:
        ans+=1 hint[i]==0 hint[i] hint i 0 count+=1 count 1 hint[i]=count hint[i] hint i count queue = deque() queue deque() deque for j in dic[i+1]:
            if hint[j-1]==0:
                queue.append(j)
                hint[j-1]=count
         j dic[i+1] dic i+1 i 1 if hint[j-1]==0:
                queue.append(j)
                hint[j-1]=count
         hint[j-1]==0 hint[j-1] hint j-1 j 1 0 queue.append(j) queue.append queue append j hint[j-1]=count hint[j-1] hint j-1 j 1 count while queue:
            x = queue.popleft()
            for k in dic[x]:
                if hint[k-1]==0:
                    hint[k-1]=count
                    queue.append(k)        
         queue x = queue.popleft() x queue.popleft() queue.popleft queue popleft for k in dic[x]:
                if hint[k-1]==0:
                    hint[k-1]=count
                    queue.append(k)        
         k dic[x] dic x if hint[k-1]==0:
                    hint[k-1]=count
                    queue.append(k)        
         hint[k-1]==0 hint[k-1] hint k-1 k 1 0 hint[k-1]=count hint[k-1] hint k-1 k 1 count queue.append(k) queue.append queue append k continue elif hint[i]==-1:
        ans+=1 hint[i]==-1 hint[i] hint i -1 ans+=1 ans 1 print(ans+count) print ans+count ans count count = 0 0 count count+=1 1 count x, y, z = map(int, input().split()) map(int, input().split()) x z = map(int, input().split()) map(int, input().split()) z ans=0 0 ans hint= [-1]*N [-1]*N hint y, z = map(int, input().split()) map(int, input().split()) y x = queue.popleft() queue.popleft() x queue = deque() deque() queue ans+=1 1 ans M = map(int, input().split()) map(int, input().split()) M dic = defaultdict(list) defaultdict(list) dic N, M = map(int, input().split()) map(int, input().split()) N
from collections import defaultdict, deque
dic = defaultdict(list)

N, M = map(int, input().split())
hint= [-1]*N

for _ in range(M):
    x, y, z = map(int, input().split())
    dic[x].append(y)
    dic[y].append(x)
    hint[x-1]=0
    hint[y-1]=0
    
count = 0
ans=0
for i in range(N):
    if hint[i]==0:
        count+=1
        hint[i]=count
        queue = deque()
        for j in dic[i+1]:
            if hint[j-1]==0:
                queue.append(j)
                hint[j-1]=count
        while queue:
            x = queue.popleft()
            for k in dic[x]:
                if hint[k-1]==0:
                    hint[k-1]=count
                    queue.append(k)        
        continue
    elif hint[i]==-1:
        ans+=1
print(ans+count)
