import sys
input = sys.stdin.readline

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
    def check(self, x, y):
        return self.find(x) == self.find(y)

N,M = map(int,input().split())
XYZ = list()
for i in range(M):
    x,y,z = map(int,input().split())
    XYZ.append((x,y,z))

uf = UnionFind(N)
for xyz in XYZ:
    x,y,z = xyz
    uf.unite(x-1,y-1)

ans = set()
for i in range(N):
    ans.add(uf.find(i))

print(len(ans)) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
    def check(self, x, y):
        return self.find(x) == self.find(y) UnionFind def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
     __init__ i for i in range(n+1) for i in range(n+1) i range(n+1) range n+1 n 1 for i in range(n+1) i self.par = [i for i in range(n+1)] self.par self par [i for i in range(n+1)] self.rank = [0] * (n+1) self.rank self rank [0] * (n+1) [0] 0 n+1 n 1 self self n n def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
     find if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
     self.par[x] == x self.par[x] self.par self par x x return x x self.par[x] = self.find(self.par[x]) self.par[x] self.par self par x self.find(self.par[x]) self.find self find self.par[x] self.par self par x return self.par[x] self.par[x] self.par self par x self self x x def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
     unite x = self.find(x) x self.find(x) self.find self find x y = self.find(y) y self.find(y) self.find self find y if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
     self.rank[x] < self.rank[y] self.rank[x] self.rank self rank x self.rank[y] self.rank self rank y self.par[x] = y self.par[x] self.par self par x y self.par[y] = x self.par[y] self.par self par y x if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
     self.rank[x] == self.rank[y] self.rank[x] self.rank self rank x self.rank[y] self.rank self rank y self.rank[x] += 1 self.rank[x] self.rank self rank x 1 self self x x y y def check(self, x, y):
        return self.find(x) == self.find(y) check return self.find(x) == self.find(y) self.find(x) == self.find(y) self.find(x) self.find self find x self.find(y) self.find self find y self self x x y y N,M = map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M XYZ = list() XYZ list() list for i in range(M):
    x,y,z = map(int,input().split())
    XYZ.append((x,y,z)) 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 XYZ.append((x,y,z)) XYZ.append XYZ append (x,y,z) x y z uf = UnionFind(N) uf UnionFind(N) UnionFind N for xyz in XYZ:
    x,y,z = xyz
    uf.unite(x-1,y-1) xyz XYZ x,y,z = xyz x xyz y z uf.unite(x-1,y-1) uf.unite uf unite x-1 x 1 y-1 y 1 ans = set() ans set() set for i in range(N):
    ans.add(uf.find(i)) i range(N) range N ans.add(uf.find(i)) ans.add ans add uf.find(i) uf.find uf find i print(len(ans)) print len(ans) len ans M = map(int,input().split()) map(int,input().split()) M ans = set() set() ans x,y,z = map(int,input().split()) map(int,input().split()) x XYZ = list() list() XYZ x,y,z = xyz xyz x input = sys.stdin.readline sys.stdin.readline input class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
    def check(self, x, y):
        return self.find(x) == self.find(y) class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
    def check(self, x, y):
        return self.find(x) == self.find(y) UnionFind N,M = map(int,input().split()) map(int,input().split()) N uf = UnionFind(N) UnionFind(N) uf z = map(int,input().split()) map(int,input().split()) z y,z = xyz xyz y z = xyz xyz z y,z = map(int,input().split()) map(int,input().split()) y
import sys
input = sys.stdin.readline

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
    def check(self, x, y):
        return self.find(x) == self.find(y)

N,M = map(int,input().split())
XYZ = list()
for i in range(M):
    x,y,z = map(int,input().split())
    XYZ.append((x,y,z))

uf = UnionFind(N)
for xyz in XYZ:
    x,y,z = xyz
    uf.unite(x-1,y-1)

ans = set()
for i in range(N):
    ans.add(uf.find(i))

print(len(ans))
