n,m=map(int,input().split())
par=[-1]*n
def find(x):
    if par[x]<0:
        return x
    else:
        par[x]=find(par[x])
        return par[x]
def union(x,y):
    x,y=find(x),find(y)
    if x!=y:
        if x>y:
            x,y=y,x
        par[x]+=par[y]
        par[y]=x

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

ans=0
for i in range(n):
    if par[i]<0:
        ans+=1
        n+=par[i]
print(ans+n) n,m=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m par=[-1]*n par [-1]*n [-1] -1 n def find(x):
    if par[x]<0:
        return x
    else:
        par[x]=find(par[x])
        return par[x] find if par[x]<0:
        return x
    else:
        par[x]=find(par[x])
        return par[x] par[x]<0 par[x] par x 0 return x x par[x]=find(par[x]) par[x] par x find(par[x]) find par[x] par x return par[x] par[x] par x x x def union(x,y):
    x,y=find(x),find(y)
    if x!=y:
        if x>y:
            x,y=y,x
        par[x]+=par[y]
        par[y]=x union x,y=find(x),find(y) x find(x) find x y find(y) find y if x!=y:
        if x>y:
            x,y=y,x
        par[x]+=par[y]
        par[y]=x x!=y x y if x>y:
            x,y=y,x
         x>y x y x,y=y,x x y y x par[x]+=par[y] par[x] par x par[y] par y par[y]=x par[y] par y x x x y y for i in range(m):
    x,y,z=map(int,input().split())
    union(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 union(x-1,y-1) union x-1 x 1 y-1 y 1 ans=0 ans 0 for i in range(n):
    if par[i]<0:
        ans+=1
        n+=par[i] i range(n) range n if par[i]<0:
        ans+=1
        n+=par[i] par[i]<0 par[i] par i 0 ans+=1 ans 1 n+=par[i] n par[i] par i print(ans+n) print ans+n ans n n,m=map(int,input().split()) map(int,input().split()) n m=map(int,input().split()) map(int,input().split()) m def find(x):
    if par[x]<0:
        return x
    else:
        par[x]=find(par[x])
        return par[x] def find(x):
    if par[x]<0:
        return x
    else:
        par[x]=find(par[x])
        return par[x] find ans+=1 1 ans n+=par[i] par[i] n def union(x,y):
    x,y=find(x),find(y)
    if x!=y:
        if x>y:
            x,y=y,x
        par[x]+=par[y]
        par[y]=x def union(x,y):
    x,y=find(x),find(y)
    if x!=y:
        if x>y:
            x,y=y,x
        par[x]+=par[y]
        par[y]=x union z=map(int,input().split()) map(int,input().split()) z ans=0 0 ans y,z=map(int,input().split()) map(int,input().split()) y par=[-1]*n [-1]*n par x,y,z=map(int,input().split()) map(int,input().split()) x
n,m=map(int,input().split())
par=[-1]*n
def find(x):
    if par[x]<0:
        return x
    else:
        par[x]=find(par[x])
        return par[x]
def union(x,y):
    x,y=find(x),find(y)
    if x!=y:
        if x>y:
            x,y=y,x
        par[x]+=par[y]
        par[y]=x

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

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