class UnionFind:

    def __init__(self, n):

        self.n = n

        self.parents = [-1] * n



    def find(self, x):

        if self.parents[x] < 0:

            return x

        else:

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

            return self.parents[x]



    def union(self, x, y):

        x = self.find(x)

        y = self.find(y)



        if x == y:

            return



        if self.parents[x] > self.parents[y]:

            x, y = y, x



        self.parents[x] += self.parents[y]

        self.parents[y] = x



    def roots(self):

        return [i for i, x in enumerate(self.parents) if x < 0]



    def group_count(self):

        return len(self.roots())





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

uf = UnionFind(n)



for _ in range(m):

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

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



print((uf.group_count()))
class UnionFind1:



    def __init__(self, n):

        self.n = n

        self.par = [-1] * (n+1)



    def root(self, x):

        if self.par[x] < 0:

            return x

        self.par[x] = self.root(self.par[x])

        return self.par[x]



    def unite(self, x, y):

        if self.same(x, y):

            return

        x = self.root(x)

        y = self.root(y)

        if self.par[x] > self.par[y]:

            x, y = y, x

        self.par[x] += self.par[y]

        self.par[y] = x



    def same(self, x, y):

        return self.root(x) == self.root(y)



    def size(self, x):

        return -self.par[self.root(x)]





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

uf = UnionFind1(n)



for _ in range(m):

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

    uf.unite(x, y)



cost = 0

for i in range(1, n+1):

    if uf.root(i) == i:

        cost += 1



print(cost)

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())


n, m = list(map(int, input().split()))
uf = UnionFind(n)
for _ in range(m):
    x, y, z = list(map(int, input().split()))
    uf.union(x - 1, y - 1)
print((uf.group_count()))

class UnionFind1:
    def __init__(self, n):
        self.n = n
        self.par = [-1] * (n + 1)

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

    def unite(self, x, y):
        if self.same(x, y):
            return
        x = self.root(x)
        y = self.root(y)
        if self.par[x] > self.par[y]:
            x, y = y, x
        self.par[x] += self.par[y]
        self.par[y] = x

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

    def size(self, x):
        return -self.par[self.root(x)]


n, m = list(map(int, input().split()))
uf = UnionFind1(n)
for _ in range(m):
    x, y, z = list(map(int, input().split()))
    uf.unite(x, y)
cost = 0
for i in range(1, n + 1):
    if uf.root(i) == i:
        cost += 1
print(cost)

-class UnionFind: +class UnionFind1: -        self.parents = [-1] * n +        self.par = [-1] * (n + 1) -    def find(self, x): -        if self.parents[x] < 0: +    def root(self, x): +        if self.par[x] < 0: -        else: -            self.parents[x] = self.find(self.parents[x]) -            return self.parents[x] +        self.par[x] = self.root(self.par[x]) +        return self.par[x] -    def union(self, x, y): -        x = self.find(x) -        y = self.find(y) -        if x == y: +    def unite(self, x, y): +        if self.same(x, y): -        if self.parents[x] > self.parents[y]: +        x = self.root(x) +        y = self.root(y) +        if self.par[x] > self.par[y]: -        self.parents[x] += self.parents[y] -        self.parents[y] = x +        self.par[x] += self.par[y] +        self.par[y] = x -    def roots(self): -        return [i for i, x in enumerate(self.parents) if x < 0] +    def same(self, x, y): +        return self.root(x) == self.root(y) -    def group_count(self): -        return len(self.roots()) +    def size(self, x): +        return -self.par[self.root(x)] -uf = UnionFind(n) +uf = UnionFind1(n) -    uf.union(x - 1, y - 1) -print((uf.group_count())) +    uf.unite(x, y) +cost = 0 +for i in range(1, n + 1): +    if uf.root(i) == i: +        cost += 1 +print(cost)