class UnionFind:
    def __init__(self, n):
        self.n = n
        self.p = [e for e in range(n)]
        self.rank = [0] * n
        self.size = [1] * n

    def same(self, u, v):
        return self.find_set(u) == self.find_set(v)

    def unite(self, u, v):
        u = self.find_set(u)
        v = self.find_set(v)

        if u == v:
            return

        if self.rank[u] > self.rank[v]:
            self.p[v] = u
            self.size[u] += self.size[v]
        else:
            self.p[u] = v
            self.size[v] += self.size[u]
            if self.rank[u] == self.rank[v]:
                self.rank[v] += 1

    def find_set(self, u):
        if u != self.p[u]:
            self.p[u] = self.find_set(self.p[u])

        return self.p[u]

    def update_p(self):
        for u in range(self.n):
            self.find_set(u)

    def get_size(self, u):
        return self.size[self.find_set(u)]


n, m = map(int, input().split())
xyz = [list(map(int, input().split())) for _ in range(m)]

uf = UnionFind(n)

for x, y, _ in xyz:
    x -= 1
    y -= 1
    uf.unite(x, y)

uf.update_p()
ans = len(set(uf.p))
print(ans) class UnionFind:
    def __init__(self, n):
        self.n = n
        self.p = [e for e in range(n)]
        self.rank = [0] * n
        self.size = [1] * n

    def same(self, u, v):
        return self.find_set(u) == self.find_set(v)

    def unite(self, u, v):
        u = self.find_set(u)
        v = self.find_set(v)

        if u == v:
            return

        if self.rank[u] > self.rank[v]:
            self.p[v] = u
            self.size[u] += self.size[v]
        else:
            self.p[u] = v
            self.size[v] += self.size[u]
            if self.rank[u] == self.rank[v]:
                self.rank[v] += 1

    def find_set(self, u):
        if u != self.p[u]:
            self.p[u] = self.find_set(self.p[u])

        return self.p[u]

    def update_p(self):
        for u in range(self.n):
            self.find_set(u)

    def get_size(self, u):
        return self.size[self.find_set(u)] UnionFind def __init__(self, n):
        self.n = n
        self.p = [e for e in range(n)]
        self.rank = [0] * n
        self.size = [1] * n

     __init__ self.n = n self.n self n n e for e in range(n) for e in range(n) e range(n) range n for e in range(n) e self.p = [e for e in range(n)] self.p self p [e for e in range(n)] self.rank = [0] * n self.rank self rank [0] * n [0] 0 n self.size = [1] * n self.size self size [1] * n [1] 1 n self self n n def same(self, u, v):
        return self.find_set(u) == self.find_set(v)

     same return self.find_set(u) == self.find_set(v) self.find_set(u) == self.find_set(v) self.find_set(u) self.find_set self find_set u self.find_set(v) self.find_set self find_set v self self u u v v def unite(self, u, v):
        u = self.find_set(u)
        v = self.find_set(v)

        if u == v:
            return

        if self.rank[u] > self.rank[v]:
            self.p[v] = u
            self.size[u] += self.size[v]
        else:
            self.p[u] = v
            self.size[v] += self.size[u]
            if self.rank[u] == self.rank[v]:
                self.rank[v] += 1

     unite u = self.find_set(u) u self.find_set(u) self.find_set self find_set u v = self.find_set(v) v self.find_set(v) self.find_set self find_set v if u == v:
            return

         u == v u v return if self.rank[u] > self.rank[v]:
            self.p[v] = u
            self.size[u] += self.size[v]
        else:
            self.p[u] = v
            self.size[v] += self.size[u]
            if self.rank[u] == self.rank[v]:
                self.rank[v] += 1

     self.rank[u] > self.rank[v] self.rank[u] self.rank self rank u self.rank[v] self.rank self rank v self.p[v] = u self.p[v] self.p self p v u self.size[u] += self.size[v] self.size[u] self.size self size u self.size[v] self.size self size v self.p[u] = v self.p[u] self.p self p u v self.size[v] += self.size[u] self.size[v] self.size self size v self.size[u] self.size self size u if self.rank[u] == self.rank[v]:
                self.rank[v] += 1

     self.rank[u] == self.rank[v] self.rank[u] self.rank self rank u self.rank[v] self.rank self rank v self.rank[v] += 1 self.rank[v] self.rank self rank v 1 self self u u v v def find_set(self, u):
        if u != self.p[u]:
            self.p[u] = self.find_set(self.p[u])

        return self.p[u]

     find_set if u != self.p[u]:
            self.p[u] = self.find_set(self.p[u])

         u != self.p[u] u self.p[u] self.p self p u self.p[u] = self.find_set(self.p[u]) self.p[u] self.p self p u self.find_set(self.p[u]) self.find_set self find_set self.p[u] self.p self p u return self.p[u] self.p[u] self.p self p u self self u u def update_p(self):
        for u in range(self.n):
            self.find_set(u)

     update_p for u in range(self.n):
            self.find_set(u)

     u range(self.n) range self.n self n self.find_set(u) self.find_set self find_set u self self def get_size(self, u):
        return self.size[self.find_set(u)] get_size return self.size[self.find_set(u)] self.size[self.find_set(u)] self.size self size self.find_set(u) self.find_set self find_set u self self u u n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m list(map(int, input().split())) for _ in range(m) for _ in range(m) _ range(m) range m for _ in range(m) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split xyz = [list(map(int, input().split())) for _ in range(m)] xyz [list(map(int, input().split())) for _ in range(m)] uf = UnionFind(n) uf UnionFind(n) UnionFind n for x, y, _ in xyz:
    x -= 1
    y -= 1
    uf.unite(x, y) x y _ xyz x -= 1 x 1 y -= 1 y 1 uf.unite(x, y) uf.unite uf unite x y uf.update_p() uf.update_p uf update_p ans = len(set(uf.p)) ans len(set(uf.p)) len set(uf.p) set uf.p uf p print(ans) print ans xyz = [list(map(int, input().split())) for _ in range(m)] [list(map(int, input().split())) for _ in range(m)] xyz x -= 1 1 x uf = UnionFind(n) UnionFind(n) uf ans = len(set(uf.p)) len(set(uf.p)) ans n, m = map(int, input().split()) map(int, input().split()) n class UnionFind:
    def __init__(self, n):
        self.n = n
        self.p = [e for e in range(n)]
        self.rank = [0] * n
        self.size = [1] * n

    def same(self, u, v):
        return self.find_set(u) == self.find_set(v)

    def unite(self, u, v):
        u = self.find_set(u)
        v = self.find_set(v)

        if u == v:
            return

        if self.rank[u] > self.rank[v]:
            self.p[v] = u
            self.size[u] += self.size[v]
        else:
            self.p[u] = v
            self.size[v] += self.size[u]
            if self.rank[u] == self.rank[v]:
                self.rank[v] += 1

    def find_set(self, u):
        if u != self.p[u]:
            self.p[u] = self.find_set(self.p[u])

        return self.p[u]

    def update_p(self):
        for u in range(self.n):
            self.find_set(u)

    def get_size(self, u):
        return self.size[self.find_set(u)] class UnionFind:
    def __init__(self, n):
        self.n = n
        self.p = [e for e in range(n)]
        self.rank = [0] * n
        self.size = [1] * n

    def same(self, u, v):
        return self.find_set(u) == self.find_set(v)

    def unite(self, u, v):
        u = self.find_set(u)
        v = self.find_set(v)

        if u == v:
            return

        if self.rank[u] > self.rank[v]:
            self.p[v] = u
            self.size[u] += self.size[v]
        else:
            self.p[u] = v
            self.size[v] += self.size[u]
            if self.rank[u] == self.rank[v]:
                self.rank[v] += 1

    def find_set(self, u):
        if u != self.p[u]:
            self.p[u] = self.find_set(self.p[u])

        return self.p[u]

    def update_p(self):
        for u in range(self.n):
            self.find_set(u)

    def get_size(self, u):
        return self.size[self.find_set(u)] UnionFind y -= 1 1 y m = map(int, input().split()) map(int, input().split()) m
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.p = [e for e in range(n)]
        self.rank = [0] * n
        self.size = [1] * n

    def same(self, u, v):
        return self.find_set(u) == self.find_set(v)

    def unite(self, u, v):
        u = self.find_set(u)
        v = self.find_set(v)

        if u == v:
            return

        if self.rank[u] > self.rank[v]:
            self.p[v] = u
            self.size[u] += self.size[v]
        else:
            self.p[u] = v
            self.size[v] += self.size[u]
            if self.rank[u] == self.rank[v]:
                self.rank[v] += 1

    def find_set(self, u):
        if u != self.p[u]:
            self.p[u] = self.find_set(self.p[u])

        return self.p[u]

    def update_p(self):
        for u in range(self.n):
            self.find_set(u)

    def get_size(self, u):
        return self.size[self.find_set(u)]


n, m = map(int, input().split())
xyz = [list(map(int, input().split())) for _ in range(m)]

uf = UnionFind(n)

for x, y, _ in xyz:
    x -= 1
    y -= 1
    uf.unite(x, y)

uf.update_p()
ans = len(set(uf.p))
print(ans)