N,M=list(map(int, input().split()))

E=[[] for _ in range(N)]

for _ in range(M):

    x,y,z=[int(i)-1 for i in input().split()]

    E[x].append(y)

    E[y].append(x)



#情報のつながりがあるカードでグルーピングする

#グループIDのリスト(0は未割り当て)

G=[0]*(N+1)



def dfs(root,g):

    stack=[root]

    G[root]=g

    while stack:

        node=stack.pop()

        for to in E[node]:

            if G[to]==0:

                G[to]=g

                stack.append(to)



ans=0

for i in range(N):

    if G[i]==0:

        ans+=1

        dfs(i,ans)



print(ans)

import sys

def main():

    input = sys.stdin.readline

    N,M=list(map(int, input().split()))



    uf = UnionFindTree(N)

    for _ in range(M):

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

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

    c=set([uf.find(i) for i in range(N)])

    print((len(c)))





class UnionFindTree:

    def __init__(self, n):

        self.parent = [-1] * n



    def find(self, x):

        p = self.parent

        while p[x] >= 0: x, p[x] = p[x], p[p[x]]

        return x



    def union(self, x, y):

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

        if x == y: return

        if p[x] > p[y]: x, y = y, x

        p[x], p[y] = p[x] + p[y], x



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

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





if __name__ == '__main__':

    main()
N, M = list(map(int, input().split()))
E = [[] for _ in range(N)]
for _ in range(M):
    x, y, z = [int(i) - 1 for i in input().split()]
    E[x].append(y)
    E[y].append(x)
# 情報のつながりがあるカードでグルーピングする
# グループIDのリスト(0は未割り当て)
G = [0] * (N + 1)


def dfs(root, g):
    stack = [root]
    G[root] = g
    while stack:
        node = stack.pop()
        for to in E[node]:
            if G[to] == 0:
                G[to] = g
                stack.append(to)


ans = 0
for i in range(N):
    if G[i] == 0:
        ans += 1
        dfs(i, ans)
print(ans)

import sys


def main():
    input = sys.stdin.readline
    N, M = list(map(int, input().split()))
    uf = UnionFindTree(N)
    for _ in range(M):
        x, y, z = list(map(int, input().split()))
        uf.union(x - 1, y - 1)
    c = set([uf.find(i) for i in range(N)])
    print((len(c)))


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

    def find(self, x):
        p = self.parent
        while p[x] >= 0:
            x, p[x] = p[x], p[p[x]]
        return x

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

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

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


if __name__ == "__main__":
    main()

-N, M = list(map(int, input().split())) -E = [[] for _ in range(N)] -for _ in range(M): -    x, y, z = [int(i) - 1 for i in input().split()] -    E[x].append(y) -    E[y].append(x) -# 情報のつながりがあるカードでグルーピングする -# グループIDのリスト(0は未割り当て) -G = [0] * (N + 1) +import sys -def dfs(root, g): -    stack = [root] -    G[root] = g -    while stack: -        node = stack.pop() -        for to in E[node]: -            if G[to] == 0: -                G[to] = g -                stack.append(to) +def main(): +    input = sys.stdin.readline +    N, M = list(map(int, input().split())) +    uf = UnionFindTree(N) +    for _ in range(M): +        x, y, z = list(map(int, input().split())) +        uf.union(x - 1, y - 1) +    c = set([uf.find(i) for i in range(N)]) +    print((len(c))) -ans = 0 -for i in range(N): -    if G[i] == 0: -        ans += 1 -        dfs(i, ans) -print(ans) +class UnionFindTree: +    def __init__(self, n): +        self.parent = [-1] * n + +    def find(self, x): +        p = self.parent +        while p[x] >= 0: +            x, p[x] = p[x], p[p[x]] +        return x + +    def union(self, x, y): +        x, y, p = self.find(x), self.find(y), self.parent +        if x == y: +            return +        if p[x] > p[y]: +            x, y = y, x +        p[x], p[y] = p[x] + p[y], x + +    def same(self, x, y): +        return self.find(x) == self.find(y) + +    def size(self, x): +        return -self.parent[self.find(x)] + + +if __name__ == "__main__": +    main()