def main():

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

    graph = {}

    for i in range(n):

        graph[i+1] = []

    for i in range(m):

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

        graph[x] += [y]

        graph[y] += [x]

    dis = [-1 for i in range (n)]

    ans = 0

    for i in range(n):

        if dis[i]==-1:

            ans += 1

            que = [i]

            dis[i] = 0

            while len(que)>0:

                s = que.pop(0)

                for nv in graph[s+1]:

                    if dis[nv-1]!=-1:

                        continue

                    dis[nv-1] = 0

                    que.append(nv-1)

    print(ans)

    

if __name__ == "__main__":

    main()

def main():

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

    cards = [-1 for i in range(n)]

    mg = {}

    for i in range(n):

        mg[i+1] = []

    for i in range(m):

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

        mg[x].append(y)

        mg[y].append(x)

    ans = 0

    for i in range(n):

        if cards[i]==-1:

            ans += 1

            cards[i] = 0

            que = [i]

            while len(que)>0:

                s = que.pop(0)

                for v in mg[s+1]:

                    if cards[v-1] == 0:

                        continue

                    cards[v-1] = 0

                    que.append(v-1)

    print(ans)



if __name__ == "__main__":

    main()

def main():
    n, m = list(map(int, input().split()))
    graph = {}
    for i in range(n):
        graph[i + 1] = []
    for i in range(m):
        x, y, z = list(map(int, input().split()))
        graph[x] += [y]
        graph[y] += [x]
    dis = [-1 for i in range(n)]
    ans = 0
    for i in range(n):
        if dis[i] == -1:
            ans += 1
            que = [i]
            dis[i] = 0
            while len(que) > 0:
                s = que.pop(0)
                for nv in graph[s + 1]:
                    if dis[nv - 1] != -1:
                        continue
                    dis[nv - 1] = 0
                    que.append(nv - 1)
    print(ans)


if __name__ == "__main__":
    main()

def main():
    n, m = list(map(int, input().split()))
    cards = [-1 for i in range(n)]
    mg = {}
    for i in range(n):
        mg[i + 1] = []
    for i in range(m):
        x, y, z = list(map(int, input().split()))
        mg[x].append(y)
        mg[y].append(x)
    ans = 0
    for i in range(n):
        if cards[i] == -1:
            ans += 1
            cards[i] = 0
            que = [i]
            while len(que) > 0:
                s = que.pop(0)
                for v in mg[s + 1]:
                    if cards[v - 1] == 0:
                        continue
                    cards[v - 1] = 0
                    que.append(v - 1)
    print(ans)


if __name__ == "__main__":
    main()

-    graph = {} +    cards = [-1 for i in range(n)] +    mg = {} -        graph[i + 1] = [] +        mg[i + 1] = [] -        graph[x] += [y] -        graph[y] += [x] -    dis = [-1 for i in range(n)] +        mg[x].append(y) +        mg[y].append(x) -        if dis[i] == -1: +        if cards[i] == -1: +            cards[i] = 0 -            dis[i] = 0 -                for nv in graph[s + 1]: -                    if dis[nv - 1] != -1: +                for v in mg[s + 1]: +                    if cards[v - 1] == 0: -                    dis[nv - 1] = 0 -                    que.append(nv - 1) +                    cards[v - 1] = 0 +                    que.append(v - 1)