class UnionFindTree:
    __slots__ = ('__tree', '__current')

    def __init__(self, n):
        self.__tree = [-1] * n
        self.__current = iter(self.__tree)

    def find(self, x):
        t = self.__tree
        if t[x] < 0:
            return x
        root = self.find(t[x])
        t[x] = root
        return root

    def union(self, x, y):
        t = self.__tree
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if t[x] > t[y]:
            x, y = y, x
        t[x] += t[y]
        t[y] = x
        return True

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.__tree[self.find(x)]

    def __next__(self):
        try:
            return next(self.__current)
        except StopIteration:
            self.__current = iter(self.__tree)
            raise StopIteration()

    def __iter__(self):
        return self


def spline(func_=int, iter_=None):
    if iter_ is None:
        iter_ = input().split()
    return map(func_, iter_)


def main():
    n, m = spline()
    tree = UnionFindTree(n)
    for i in range(1, m + 1):
        x, y, _ = spline(func_=lambda x: int(x) - 1)
        tree.union(x, y)
    ans = 0
    for i in tree:
        if i < 0:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main() class UnionFindTree:
    __slots__ = ('__tree', '__current')

    def __init__(self, n):
        self.__tree = [-1] * n
        self.__current = iter(self.__tree)

    def find(self, x):
        t = self.__tree
        if t[x] < 0:
            return x
        root = self.find(t[x])
        t[x] = root
        return root

    def union(self, x, y):
        t = self.__tree
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if t[x] > t[y]:
            x, y = y, x
        t[x] += t[y]
        t[y] = x
        return True

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.__tree[self.find(x)]

    def __next__(self):
        try:
            return next(self.__current)
        except StopIteration:
            self.__current = iter(self.__tree)
            raise StopIteration()

    def __iter__(self):
        return self UnionFindTree __slots__ = ('__tree', '__current') __slots__ ('__tree', '__current') '__tree' '__current' def __init__(self, n):
        self.__tree = [-1] * n
        self.__current = iter(self.__tree)

     __init__ self.__tree = [-1] * n self.__tree self __tree [-1] * n [-1] -1 n self.__current = iter(self.__tree) self.__current self __current iter(self.__tree) iter self.__tree self __tree self self n n def find(self, x):
        t = self.__tree
        if t[x] < 0:
            return x
        root = self.find(t[x])
        t[x] = root
        return root

     find t = self.__tree t self.__tree self __tree if t[x] < 0:
            return x
         t[x] < 0 t[x] t x 0 return x x root = self.find(t[x]) root self.find(t[x]) self.find self find t[x] t x t[x] = root t[x] t x root return root root self self x x def union(self, x, y):
        t = self.__tree
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if t[x] > t[y]:
            x, y = y, x
        t[x] += t[y]
        t[y] = x
        return True

     union t = self.__tree t self.__tree self __tree 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 x == y:
            return False
         x == y x y return False False if t[x] > t[y]:
            x, y = y, x
         t[x] > t[y] t[x] t x t[y] t y x, y = y, x x y y x t[x] += t[y] t[x] t x t[y] t y t[y] = x t[y] t y x return True True self self x x y y def same(self, x, y):
        return self.find(x) == self.find(y)

     same 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 def size(self, x):
        return -self.__tree[self.find(x)]

     size return -self.__tree[self.find(x)] -self.__tree[self.find(x)] self.__tree[self.find(x)] self.__tree self __tree self.find(x) self.find self find x self self x x def __next__(self):
        try:
            return next(self.__current)
        except StopIteration:
            self.__current = iter(self.__tree)
            raise StopIteration()

     __next__ try:
            return next(self.__current)
        except StopIteration:
            self.__current = iter(self.__tree)
            raise StopIteration()

     except StopIteration:
            self.__current = iter(self.__tree)
            raise StopIteration()

     self.__current = iter(self.__tree) self.__current self __current iter(self.__tree) iter self.__tree self __tree raise StopIteration() StopIteration() StopIteration return next(self.__current) next(self.__current) next self.__current self __current self self def __iter__(self):
        return self __iter__ return self self self self def spline(func_=int, iter_=None):
    if iter_ is None:
        iter_ = input().split()
    return map(func_, iter_) spline if iter_ is None:
        iter_ = input().split()
     iter_ is None iter_ None iter_ = input().split() iter_ input().split() ().split () input split return map(func_, iter_) map(func_, iter_) map func_ iter_ func_=int func_ int iter_=None iter_ None def main():
    n, m = spline()
    tree = UnionFindTree(n)
    for i in range(1, m + 1):
        x, y, _ = spline(func_=lambda x: int(x) - 1)
        tree.union(x, y)
    ans = 0
    for i in tree:
        if i < 0:
            ans += 1
    print(ans) main n, m = spline() n spline() spline m tree = UnionFindTree(n) tree UnionFindTree(n) UnionFindTree n for i in range(1, m + 1):
        x, y, _ = spline(func_=lambda x: int(x) - 1)
        tree.union(x, y)
     i range(1, m + 1) range 1 m + 1 m 1 x, y, _ = spline(func_=lambda x: int(x) - 1) x spline(func_=lambda x: int(x) - 1) spline func_=lambda x: int(x) - 1 func_ lambda x: int(x) - 1 int(x) - 1 int(x) int x 1 x y _ tree.union(x, y) tree.union tree union x y ans = 0 ans 0 for i in tree:
        if i < 0:
            ans += 1
     i tree if i < 0:
            ans += 1
     i < 0 i 0 ans += 1 ans 1 print(ans) print ans if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main class UnionFindTree:
    __slots__ = ('__tree', '__current')

    def __init__(self, n):
        self.__tree = [-1] * n
        self.__current = iter(self.__tree)

    def find(self, x):
        t = self.__tree
        if t[x] < 0:
            return x
        root = self.find(t[x])
        t[x] = root
        return root

    def union(self, x, y):
        t = self.__tree
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if t[x] > t[y]:
            x, y = y, x
        t[x] += t[y]
        t[y] = x
        return True

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.__tree[self.find(x)]

    def __next__(self):
        try:
            return next(self.__current)
        except StopIteration:
            self.__current = iter(self.__tree)
            raise StopIteration()

    def __iter__(self):
        return self class UnionFindTree:
    __slots__ = ('__tree', '__current')

    def __init__(self, n):
        self.__tree = [-1] * n
        self.__current = iter(self.__tree)

    def find(self, x):
        t = self.__tree
        if t[x] < 0:
            return x
        root = self.find(t[x])
        t[x] = root
        return root

    def union(self, x, y):
        t = self.__tree
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if t[x] > t[y]:
            x, y = y, x
        t[x] += t[y]
        t[y] = x
        return True

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.__tree[self.find(x)]

    def __next__(self):
        try:
            return next(self.__current)
        except StopIteration:
            self.__current = iter(self.__tree)
            raise StopIteration()

    def __iter__(self):
        return self UnionFindTree def main():
    n, m = spline()
    tree = UnionFindTree(n)
    for i in range(1, m + 1):
        x, y, _ = spline(func_=lambda x: int(x) - 1)
        tree.union(x, y)
    ans = 0
    for i in tree:
        if i < 0:
            ans += 1
    print(ans) def main():
    n, m = spline()
    tree = UnionFindTree(n)
    for i in range(1, m + 1):
        x, y, _ = spline(func_=lambda x: int(x) - 1)
        tree.union(x, y)
    ans = 0
    for i in tree:
        if i < 0:
            ans += 1
    print(ans) main def spline(func_=int, iter_=None):
    if iter_ is None:
        iter_ = input().split()
    return map(func_, iter_) def spline(func_=int, iter_=None):
    if iter_ is None:
        iter_ = input().split()
    return map(func_, iter_) spline
class UnionFindTree:
    __slots__ = ('__tree', '__current')

    def __init__(self, n):
        self.__tree = [-1] * n
        self.__current = iter(self.__tree)

    def find(self, x):
        t = self.__tree
        if t[x] < 0:
            return x
        root = self.find(t[x])
        t[x] = root
        return root

    def union(self, x, y):
        t = self.__tree
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if t[x] > t[y]:
            x, y = y, x
        t[x] += t[y]
        t[y] = x
        return True

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.__tree[self.find(x)]

    def __next__(self):
        try:
            return next(self.__current)
        except StopIteration:
            self.__current = iter(self.__tree)
            raise StopIteration()

    def __iter__(self):
        return self


def spline(func_=int, iter_=None):
    if iter_ is None:
        iter_ = input().split()
    return map(func_, iter_)


def main():
    n, m = spline()
    tree = UnionFindTree(n)
    for i in range(1, m + 1):
        x, y, _ = spline(func_=lambda x: int(x) - 1)
        tree.union(x, y)
    ans = 0
    for i in tree:
        if i < 0:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()
