class UnionFind:

    def __init__(self, n):

        self.n = n

        self.parents = list(range(n + 1))

        self.ranks = [0 for _ in range(n + 1)]



    def get_root(self, x):

        if self.parents[x] == x:

            return x

        self.parents[x] = self.get_root(self.parents[x])

        return self.parents[x]



    def merge(self, x, y):

        x = self.get_root(x)

        y = self.get_root(y)

        if x != y:

            if self.ranks[x] < self.ranks[y]:

                self.parents[x] = y

            else:

                self.parents[y] = x

                if self.ranks[x] == self.ranks[y]:

                    self.ranks[x] += 1





n, m = list(map(int, input().split()))

uf = UnionFind(n)

for _ in range(m):

    x, y, z = list(map(int, input().split()))

    uf.merge(x - 1, y - 1)

res = set()

for i in range(n):

    res.add(uf.get_root(i))

print((len(res)))
import sys



input = sys.stdin.readline



ri = lambda: int(eval(input()))

rs = lambda: input().rstrip()

ril = lambda: list(map(int, input().split()))

rsl = lambda: input().rstrip().split()

ris = lambda n: [ri() for _ in range(n)]

rss = lambda n: [rs() for _ in range(n)]

rils = lambda n: [ril() for _ in range(n)]

rsls = lambda n: [rsl() for _ in range(n)]





class UnionFind:

    def __init__(self, n):

        self.n = n

        self.parents = list(range(n))

        self.ranks = [0 for _ in range(n)]



    def get_root(self, x):

        if self.parents[x] == x:

            return x

        self.parents[x] = self.get_root(self.parents[x])

        return self.parents[x]



    def merge(self, x, y):

        x = self.get_root(x)

        y = self.get_root(y)

        if x != y:

            if self.ranks[x] < self.ranks[y]:

                self.parents[x] = y

            else:

                self.parents[y] = x

                if self.ranks[x] == self.ranks[y]:

                    self.ranks[x] += 1





n, m = ril()

uf = UnionFind(n)

for _ in range(m):

    x, y, z = ril()

    uf.merge(x - 1, y - 1)

res = set()

for i in range(n):

    res.add(uf.get_root(i))

print((len(res)))
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = list(range(n + 1))
        self.ranks = [0 for _ in range(n + 1)]

    def get_root(self, x):
        if self.parents[x] == x:
            return x
        self.parents[x] = self.get_root(self.parents[x])
        return self.parents[x]

    def merge(self, x, y):
        x = self.get_root(x)
        y = self.get_root(y)
        if x != y:
            if self.ranks[x] < self.ranks[y]:
                self.parents[x] = y
            else:
                self.parents[y] = x
                if self.ranks[x] == self.ranks[y]:
                    self.ranks[x] += 1


n, m = list(map(int, input().split()))
uf = UnionFind(n)
for _ in range(m):
    x, y, z = list(map(int, input().split()))
    uf.merge(x - 1, y - 1)
res = set()
for i in range(n):
    res.add(uf.get_root(i))
print((len(res)))

import sys

input = sys.stdin.readline
ri = lambda: int(eval(input()))
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]


class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = list(range(n))
        self.ranks = [0 for _ in range(n)]

    def get_root(self, x):
        if self.parents[x] == x:
            return x
        self.parents[x] = self.get_root(self.parents[x])
        return self.parents[x]

    def merge(self, x, y):
        x = self.get_root(x)
        y = self.get_root(y)
        if x != y:
            if self.ranks[x] < self.ranks[y]:
                self.parents[x] = y
            else:
                self.parents[y] = x
                if self.ranks[x] == self.ranks[y]:
                    self.ranks[x] += 1


n, m = ril()
uf = UnionFind(n)
for _ in range(m):
    x, y, z = ril()
    uf.merge(x - 1, y - 1)
res = set()
for i in range(n):
    res.add(uf.get_root(i))
print((len(res)))

+import sys + +input = sys.stdin.readline +ri = lambda: int(eval(input())) +rs = lambda: input().rstrip() +ril = lambda: list(map(int, input().split())) +rsl = lambda: input().rstrip().split() +ris = lambda n: [ri() for _ in range(n)] +rss = lambda n: [rs() for _ in range(n)] +rils = lambda n: [ril() for _ in range(n)] +rsls = lambda n: [rsl() for _ in range(n)] + + -        self.parents = list(range(n + 1)) -        self.ranks = [0 for _ in range(n + 1)] +        self.parents = list(range(n)) +        self.ranks = [0 for _ in range(n)] -n, m = list(map(int, input().split())) +n, m = ril() -    x, y, z = list(map(int, input().split())) +    x, y, z = ril()