# ABC126E - 1 or 2

import sys



sys.setrecursionlimit(10 ** 9)





def dfs(v: int) -> None:

    for u in G[v]:

        if not visited[u]:

            visited[u] = color

            dfs(u)





def main():

    global G, visited, color

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

    G = [[] for _ in range(N + 1)]

    for v, u in zip(X[::3], X[1::3]):

        G[v].append(u), G[u].append(v)

    visited, color = [0] * (N + 1), 1

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

        if not visited[v]:

            visited[v] = color

            dfs(v)

            color += 1

    ans = color - 1

    print(ans)





if __name__ == "__main__":

    main()
# E - 1 or 2

from typing import List





def main():

    def dfs(source: int) -> None:

        stack = [source]

        is_visited[source] = True

        while stack:

            u = stack.pop()

            for v in graph[u]:

                if is_visited[v]:

                    continue

                is_visited[v] = True

                stack.append(v)



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

    graph: List[List[int]] = [[] for _ in range(N + 1)]

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

        graph[x].append(y), graph[y].append(x)



    is_visited = [False] * (N + 1)

    res = 0

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

        if is_visited[i]:

            continue

        res += 1

        dfs(i)

    print(res)





if __name__ == "__main__":

    main()

# ABC126E - 1 or 2
import sys

sys.setrecursionlimit(10**9)


def dfs(v: int) -> None:
    for u in G[v]:
        if not visited[u]:
            visited[u] = color
            dfs(u)


def main():
    global G, visited, color
    N, M, *X = list(map(int, open(0).read().split()))
    G = [[] for _ in range(N + 1)]
    for v, u in zip(X[::3], X[1::3]):
        G[v].append(u), G[u].append(v)
    visited, color = [0] * (N + 1), 1
    for v in range(1, N + 1):
        if not visited[v]:
            visited[v] = color
            dfs(v)
            color += 1
    ans = color - 1
    print(ans)


if __name__ == "__main__":
    main()

# E - 1 or 2
from typing import List


def main():
    def dfs(source: int) -> None:
        stack = [source]
        is_visited[source] = True
        while stack:
            u = stack.pop()
            for v in graph[u]:
                if is_visited[v]:
                    continue
                is_visited[v] = True
                stack.append(v)

    N, M, *X = list(map(int, open(0).read().split()))
    graph: List[List[int]] = [[] for _ in range(N + 1)]
    for x, y, _ in zip(*[iter(X)] * 3):
        graph[x].append(y), graph[y].append(x)
    is_visited = [False] * (N + 1)
    res = 0
    for i in range(1, N + 1):
        if is_visited[i]:
            continue
        res += 1
        dfs(i)
    print(res)


if __name__ == "__main__":
    main()

-# ABC126E - 1 or 2 -import sys - -sys.setrecursionlimit(10**9) - - -def dfs(v: int) -> None: -    for u in G[v]: -        if not visited[u]: -            visited[u] = color -            dfs(u) +# E - 1 or 2 +from typing import List -    global G, visited, color +    def dfs(source: int) -> None: +        stack = [source] +        is_visited[source] = True +        while stack: +            u = stack.pop() +            for v in graph[u]: +                if is_visited[v]: +                    continue +                is_visited[v] = True +                stack.append(v) + -    G = [[] for _ in range(N + 1)] -    for v, u in zip(X[::3], X[1::3]): -        G[v].append(u), G[u].append(v) -    visited, color = [0] * (N + 1), 1 -    for v in range(1, N + 1): -        if not visited[v]: -            visited[v] = color -            dfs(v) -            color += 1 -    ans = color - 1 -    print(ans) +    graph: List[List[int]] = [[] for _ in range(N + 1)] +    for x, y, _ in zip(*[iter(X)] * 3): +        graph[x].append(y), graph[y].append(x) +    is_visited = [False] * (N + 1) +    res = 0 +    for i in range(1, N + 1): +        if is_visited[i]: +            continue +        res += 1 +        dfs(i) +    print(res)