import sys
sys.setrecursionlimit(10**6)
n, m = map(int, input().split())
xy = []
for _ in range(m):
    x, y, _ = map(int, input().split())
    xy.append((x-1, y-1))

class UnionFind():
    def __init__(self, n):
        self.li = list(range(n))
    def root(self, x):
        if self.li[x]==x:
            return x
        self.li[x] = self.root(self.li[x])
        return self.li[x]
    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx==ry:
            return
        self.li[ry] = rx
    def same(self, x, y):
        return self.root(x)==self.root(y)

uf = UnionFind(n)
for x, y in xy:
    uf.unite(x, y)
for i in range(n):
    uf.root(i)
print(len(set(uf.li))) import sys sys sys.setrecursionlimit(10**6) sys.setrecursionlimit sys setrecursionlimit 10**6 10 6 n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m xy = [] xy [] for _ in range(m):
    x, y, _ = map(int, input().split())
    xy.append((x-1, y-1)) _ range(m) range m x, y, _ = map(int, input().split()) x map(int, input().split()) map int input().split() ().split () input split y _ xy.append((x-1, y-1)) xy.append xy append (x-1, y-1) x-1 x 1 y-1 y 1 class UnionFind():
    def __init__(self, n):
        self.li = list(range(n))
    def root(self, x):
        if self.li[x]==x:
            return x
        self.li[x] = self.root(self.li[x])
        return self.li[x]
    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx==ry:
            return
        self.li[ry] = rx
    def same(self, x, y):
        return self.root(x)==self.root(y) UnionFind def __init__(self, n):
        self.li = list(range(n))
     __init__ self.li = list(range(n)) self.li self li list(range(n)) list range(n) range n self self n n def root(self, x):
        if self.li[x]==x:
            return x
        self.li[x] = self.root(self.li[x])
        return self.li[x]
     root if self.li[x]==x:
            return x
         self.li[x]==x self.li[x] self.li self li x x return x x self.li[x] = self.root(self.li[x]) self.li[x] self.li self li x self.root(self.li[x]) self.root self root self.li[x] self.li self li x return self.li[x] self.li[x] self.li self li x self self x x def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx==ry:
            return
        self.li[ry] = rx
     unite rx = self.root(x) rx self.root(x) self.root self root x ry = self.root(y) ry self.root(y) self.root self root y if rx==ry:
            return
         rx==ry rx ry return self.li[ry] = rx self.li[ry] self.li self li ry rx self self x x y y def same(self, x, y):
        return self.root(x)==self.root(y) same return self.root(x)==self.root(y) self.root(x)==self.root(y) self.root(x) self.root self root x self.root(y) self.root self root y self self x x y y uf = UnionFind(n) uf UnionFind(n) UnionFind n for x, y in xy:
    uf.unite(x, y) x y xy uf.unite(x, y) uf.unite uf unite x y for i in range(n):
    uf.root(i) i range(n) range n uf.root(i) uf.root uf root i print(len(set(uf.li))) print len(set(uf.li)) len set(uf.li) set uf.li uf li xy = [] [] xy n, m = map(int, input().split()) map(int, input().split()) n class UnionFind():
    def __init__(self, n):
        self.li = list(range(n))
    def root(self, x):
        if self.li[x]==x:
            return x
        self.li[x] = self.root(self.li[x])
        return self.li[x]
    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx==ry:
            return
        self.li[ry] = rx
    def same(self, x, y):
        return self.root(x)==self.root(y) class UnionFind():
    def __init__(self, n):
        self.li = list(range(n))
    def root(self, x):
        if self.li[x]==x:
            return x
        self.li[x] = self.root(self.li[x])
        return self.li[x]
    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx==ry:
            return
        self.li[ry] = rx
    def same(self, x, y):
        return self.root(x)==self.root(y) UnionFind m = map(int, input().split()) map(int, input().split()) m x, y, _ = map(int, input().split()) map(int, input().split()) x _ = map(int, input().split()) map(int, input().split()) _ y, _ = map(int, input().split()) map(int, input().split()) y uf = UnionFind(n) UnionFind(n) uf
import sys
sys.setrecursionlimit(10**6)
n, m = map(int, input().split())
xy = []
for _ in range(m):
    x, y, _ = map(int, input().split())
    xy.append((x-1, y-1))

class UnionFind():
    def __init__(self, n):
        self.li = list(range(n))
    def root(self, x):
        if self.li[x]==x:
            return x
        self.li[x] = self.root(self.li[x])
        return self.li[x]
    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx==ry:
            return
        self.li[ry] = rx
    def same(self, x, y):
        return self.root(x)==self.root(y)

uf = UnionFind(n)
for x, y in xy:
    uf.unite(x, y)
for i in range(n):
    uf.root(i)
print(len(set(uf.li)))