from collections import deque
N, M = map(int, input().split())
Clear = [-1]*N
T = [[] for _ in range(N)]
ans = 0
for i in range(M):
    X, Y, Z = map(int, input().split())
    X -= 1
    Y -= 1
    T[X].append(Y)
    T[Y].append(X)

for i in range(N):
    if Clear[i] == -1:
        ans += 1
        Clear[i] = 1
        P = deque([i])
        while(len(P) > 0):
            t = P.popleft()
            for j in T[t]:
                if Clear[j] == -1:
                    Clear[j] = 1
                    P.append(j)
print(ans) from collections import deque N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M Clear = [-1]*N Clear [-1]*N [-1] -1 N [] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [] T = [[] for _ in range(N)] T [[] for _ in range(N)] ans = 0 ans 0 for i in range(M):
    X, Y, Z = map(int, input().split())
    X -= 1
    Y -= 1
    T[X].append(Y)
    T[Y].append(X) 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 X -= 1 X 1 Y -= 1 Y 1 T[X].append(Y) [X].append [X] T X append Y T[Y].append(X) [Y].append [Y] T Y append X for i in range(N):
    if Clear[i] == -1:
        ans += 1
        Clear[i] = 1
        P = deque([i])
        while(len(P) > 0):
            t = P.popleft()
            for j in T[t]:
                if Clear[j] == -1:
                    Clear[j] = 1
                    P.append(j) i range(N) range N if Clear[i] == -1:
        ans += 1
        Clear[i] = 1
        P = deque([i])
        while(len(P) > 0):
            t = P.popleft()
            for j in T[t]:
                if Clear[j] == -1:
                    Clear[j] = 1
                    P.append(j) Clear[i] == -1 Clear[i] Clear i -1 ans += 1 ans 1 Clear[i] = 1 Clear[i] Clear i 1 P = deque([i]) P deque([i]) deque [i] i while(len(P) > 0):
            t = P.popleft()
            for j in T[t]:
                if Clear[j] == -1:
                    Clear[j] = 1
                    P.append(j) len(P) > 0 len(P) len P 0 t = P.popleft() t P.popleft() P.popleft P popleft for j in T[t]:
                if Clear[j] == -1:
                    Clear[j] = 1
                    P.append(j) j T[t] T t if Clear[j] == -1:
                    Clear[j] = 1
                    P.append(j) Clear[j] == -1 Clear[j] Clear j -1 Clear[j] = 1 Clear[j] Clear j 1 P.append(j) P.append P append j print(ans) print ans Z = map(int, input().split()) map(int, input().split()) Z Y, Z = map(int, input().split()) map(int, input().split()) Y M = map(int, input().split()) map(int, input().split()) M X -= 1 1 X T = [[] for _ in range(N)] [[] for _ in range(N)] T N, M = map(int, input().split()) map(int, input().split()) N ans += 1 1 ans Y -= 1 1 Y Clear = [-1]*N [-1]*N Clear X, Y, Z = map(int, input().split()) map(int, input().split()) X P = deque([i]) deque([i]) P t = P.popleft() P.popleft() t ans = 0 0 ans
from collections import deque
N, M = map(int, input().split())
Clear = [-1]*N
T = [[] for _ in range(N)]
ans = 0
for i in range(M):
    X, Y, Z = map(int, input().split())
    X -= 1
    Y -= 1
    T[X].append(Y)
    T[Y].append(X)

for i in range(N):
    if Clear[i] == -1:
        ans += 1
        Clear[i] = 1
        P = deque([i])
        while(len(P) > 0):
            t = P.popleft()
            for j in T[t]:
                if Clear[j] == -1:
                    Clear[j] = 1
                    P.append(j)
print(ans)