class UnionFind:
    N = 0
    cost = 0
    par = []
    group = 0
    
    def init(N):
        UnionFind.N = N
        UnionFind.group = N
        UnionFind.par = [i for i in range(N)]

    def find(v):
        c = 0
        u = v
        while v != UnionFind.par[v]:
            v = UnionFind.par[v]
            c += 1

        if c > 10:
            while u != v: u, UnionFind.par[u] = UnionFind.par[u], v

        return v

    def union(v, u, c=0):
        vr = UnionFind.find(v)
        ur = UnionFind.find(u)

        if vr == ur: return True

        UnionFind.par[ur] = vr
        UnionFind.cost += c
        UnionFind.group -= 1
        
        return False
            
    def get_cost():
        return UnionFind.cost

    def get_group():
        return UnionFind.group

    def same(v, u):
        return UnionFind.find(v) == UnionFind.find(u)

N, M = list(map(int, input().split()))
UnionFind.init(N)

for i in range(M):
    x, y, _ = list(map(int, input().split()))
    x -= 1; y -= 1

    UnionFind.union(x, y)

print(UnionFind.get_group()) class UnionFind:
    N = 0
    cost = 0
    par = []
    group = 0
    
    def init(N):
        UnionFind.N = N
        UnionFind.group = N
        UnionFind.par = [i for i in range(N)]

    def find(v):
        c = 0
        u = v
        while v != UnionFind.par[v]:
            v = UnionFind.par[v]
            c += 1

        if c > 10:
            while u != v: u, UnionFind.par[u] = UnionFind.par[u], v

        return v

    def union(v, u, c=0):
        vr = UnionFind.find(v)
        ur = UnionFind.find(u)

        if vr == ur: return True

        UnionFind.par[ur] = vr
        UnionFind.cost += c
        UnionFind.group -= 1
        
        return False
            
    def get_cost():
        return UnionFind.cost

    def get_group():
        return UnionFind.group

    def same(v, u):
        return UnionFind.find(v) == UnionFind.find(u) UnionFind N = 0 N 0 cost = 0 cost 0 par = [] par [] group = 0 group 0 def init(N):
        UnionFind.N = N
        UnionFind.group = N
        UnionFind.par = [i for i in range(N)]

     init UnionFind.N = N UnionFind.N UnionFind N N UnionFind.group = N UnionFind.group UnionFind group N i for i in range(N) for i in range(N) i range(N) range N for i in range(N) i UnionFind.par = [i for i in range(N)] UnionFind.par UnionFind par [i for i in range(N)] N N def find(v):
        c = 0
        u = v
        while v != UnionFind.par[v]:
            v = UnionFind.par[v]
            c += 1

        if c > 10:
            while u != v: u, UnionFind.par[u] = UnionFind.par[u], v

        return v

     find c = 0 c 0 u = v u v while v != UnionFind.par[v]:
            v = UnionFind.par[v]
            c += 1

         v != UnionFind.par[v] v UnionFind.par[v] UnionFind.par UnionFind par v v = UnionFind.par[v] v UnionFind.par[v] UnionFind.par UnionFind par v c += 1 c 1 if c > 10:
            while u != v: u, UnionFind.par[u] = UnionFind.par[u], v

         c > 10 c 10 while u != v: u, UnionFind.par[u] = UnionFind.par[u], v

         u != v u v return v v v v def union(v, u, c=0):
        vr = UnionFind.find(v)
        ur = UnionFind.find(u)

        if vr == ur: return True

        UnionFind.par[ur] = vr
        UnionFind.cost += c
        UnionFind.group -= 1
        
        return False
            
     union vr = UnionFind.find(v) vr UnionFind.find(v) UnionFind.find UnionFind find v ur = UnionFind.find(u) ur UnionFind.find(u) UnionFind.find UnionFind find u if vr == ur: return True

         vr == ur vr ur UnionFind.par[ur] = vr UnionFind.par[ur] UnionFind.par UnionFind par ur vr UnionFind.cost += c UnionFind.cost UnionFind cost c UnionFind.group -= 1 UnionFind.group UnionFind group 1 return False False v v u u c=0 c 0 def get_cost():
        return UnionFind.cost

     get_cost return UnionFind.cost UnionFind.cost UnionFind cost def get_group():
        return UnionFind.group

     get_group return UnionFind.group UnionFind.group UnionFind group def same(v, u):
        return UnionFind.find(v) == UnionFind.find(u) same return UnionFind.find(v) == UnionFind.find(u) UnionFind.find(v) == UnionFind.find(u) UnionFind.find(v) UnionFind.find UnionFind find v UnionFind.find(u) UnionFind.find UnionFind find u v v u u N, M = list(map(int, input().split())) N list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split M UnionFind.init(N) UnionFind.init UnionFind init N for i in range(M):
    x, y, _ = list(map(int, input().split()))
    x -= 1; y -= 1

    UnionFind.union(x, y) i range(M) range M x, y, _ = list(map(int, input().split())) x list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split y _ x -= 1 x 1 y -= 1 y 1 UnionFind.union(x, y) UnionFind.union UnionFind union x y print(UnionFind.get_group()) print UnionFind.get_group() UnionFind.get_group UnionFind get_group y, _ = list(map(int, input().split())) list(map(int, input().split())) y y -= 1 1 y M = list(map(int, input().split())) list(map(int, input().split())) M class UnionFind:
    N = 0
    cost = 0
    par = []
    group = 0
    
    def init(N):
        UnionFind.N = N
        UnionFind.group = N
        UnionFind.par = [i for i in range(N)]

    def find(v):
        c = 0
        u = v
        while v != UnionFind.par[v]:
            v = UnionFind.par[v]
            c += 1

        if c > 10:
            while u != v: u, UnionFind.par[u] = UnionFind.par[u], v

        return v

    def union(v, u, c=0):
        vr = UnionFind.find(v)
        ur = UnionFind.find(u)

        if vr == ur: return True

        UnionFind.par[ur] = vr
        UnionFind.cost += c
        UnionFind.group -= 1
        
        return False
            
    def get_cost():
        return UnionFind.cost

    def get_group():
        return UnionFind.group

    def same(v, u):
        return UnionFind.find(v) == UnionFind.find(u) class UnionFind:
    N = 0
    cost = 0
    par = []
    group = 0
    
    def init(N):
        UnionFind.N = N
        UnionFind.group = N
        UnionFind.par = [i for i in range(N)]

    def find(v):
        c = 0
        u = v
        while v != UnionFind.par[v]:
            v = UnionFind.par[v]
            c += 1

        if c > 10:
            while u != v: u, UnionFind.par[u] = UnionFind.par[u], v

        return v

    def union(v, u, c=0):
        vr = UnionFind.find(v)
        ur = UnionFind.find(u)

        if vr == ur: return True

        UnionFind.par[ur] = vr
        UnionFind.cost += c
        UnionFind.group -= 1
        
        return False
            
    def get_cost():
        return UnionFind.cost

    def get_group():
        return UnionFind.group

    def same(v, u):
        return UnionFind.find(v) == UnionFind.find(u) UnionFind _ = list(map(int, input().split())) list(map(int, input().split())) _ x -= 1 1 x N, M = list(map(int, input().split())) list(map(int, input().split())) N x, y, _ = list(map(int, input().split())) list(map(int, input().split())) x
class UnionFind:
    N = 0
    cost = 0
    par = []
    group = 0
    
    def init(N):
        UnionFind.N = N
        UnionFind.group = N
        UnionFind.par = [i for i in range(N)]

    def find(v):
        c = 0
        u = v
        while v != UnionFind.par[v]:
            v = UnionFind.par[v]
            c += 1

        if c > 10:
            while u != v: u, UnionFind.par[u] = UnionFind.par[u], v

        return v

    def union(v, u, c=0):
        vr = UnionFind.find(v)
        ur = UnionFind.find(u)

        if vr == ur: return True

        UnionFind.par[ur] = vr
        UnionFind.cost += c
        UnionFind.group -= 1
        
        return False
            
    def get_cost():
        return UnionFind.cost

    def get_group():
        return UnionFind.group

    def same(v, u):
        return UnionFind.find(v) == UnionFind.find(u)

N, M = list(map(int, input().split()))
UnionFind.init(N)

for i in range(M):
    x, y, _ = list(map(int, input().split()))
    x -= 1; y -= 1

    UnionFind.union(x, y)

print(UnionFind.get_group())