class UnionFind:

    def __init__(self, size):

        self.data = [-1 for _ in range(size)]

    def find(self, x):

        if self.data[x] < 0:

            return x

        else:

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

            return self.data[x]

    def union(self, x, y):

        x, y = self.find(x), self.find(y)

        if x != y:

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

                x, y = y, x

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

            self.data[y] = x

        return (x != y)

    def same(self, x, y):

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

    def size(self, x):

        return -self.data[self.find(x)]





N, M = [int(i) for i in input().split()]



uf = UnionFind(N + 1)

for x, y, z in [[int(i) for i in input().split()] for _ in range(M)]:

    uf.union(x, y)



s = set()

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

    s.add(uf.find(i))



print((len(s)))
class UnionFind:

    def __init__(self, size):

        self.data = [-1 for _ in range(size)]

    def find(self, x):

        if self.data[x] < 0:

            return x

        else:

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

            return self.data[x]

    def union(self, x, y):

        x, y = self.find(x), self.find(y)

        if x != y:

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

                x, y = y, x

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

            self.data[y] = x

        return (x != y)

    def same(self, x, y):

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

    def size(self, x):

        return -self.data[self.find(x)]





N, M, *XYZ = list(map(int, open(0).read().split()))



uf = UnionFind(N + 1)

for x, y, _ in zip(*[iter(XYZ)] * 3):

    uf.union(x, y)



print((len({uf.find(i + 1) for i in range(N)})))

class UnionFind:
    def __init__(self, size):
        self.data = [-1 for _ in range(size)]

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

    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x != y:
            if self.data[y] < self.data[x]:
                x, y = y, x
            self.data[x] += self.data[y]
            self.data[y] = x
        return x != y

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

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


N, M = [int(i) for i in input().split()]
uf = UnionFind(N + 1)
for x, y, z in [[int(i) for i in input().split()] for _ in range(M)]:
    uf.union(x, y)
s = set()
for i in range(1, N + 1):
    s.add(uf.find(i))
print((len(s)))

class UnionFind:
    def __init__(self, size):
        self.data = [-1 for _ in range(size)]

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

    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x != y:
            if self.data[y] < self.data[x]:
                x, y = y, x
            self.data[x] += self.data[y]
            self.data[y] = x
        return x != y

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

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


N, M, *XYZ = list(map(int, open(0).read().split()))
uf = UnionFind(N + 1)
for x, y, _ in zip(*[iter(XYZ)] * 3):
    uf.union(x, y)
print((len({uf.find(i + 1) for i in range(N)})))

-N, M = [int(i) for i in input().split()] +N, M, *XYZ = list(map(int, open(0).read().split())) -for x, y, z in [[int(i) for i in input().split()] for _ in range(M)]: +for x, y, _ in zip(*[iter(XYZ)] * 3): -s = set() -for i in range(1, N + 1): -    s.add(uf.find(i)) -print((len(s))) +print((len({uf.find(i + 1) for i in range(N)})))