import sys

sys.setrecursionlimit(10**6)



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

t = [[] for i in range(n)]

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

for i in range(m):

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

    x -= 1

    y -= 1

    t[x].append(y)

    t[y].append(x)





def dfs(num, depth):

    if c[num] != -1:

        return

    else:

        c[num] = depth

    for i in t[num]:

        dfs(i, depth)





cnt = 0

for i in range(n):

    if c[i] == -1:

        cnt += 1

        dfs(i, cnt)



print((max(c)))

import sys

sys.setrecursionlimit(10**6)



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

t = [[] for i in range(n)]

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

for line in sys.stdin:

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

    x -= 1

    y -= 1

    t[x].append(y)

    t[y].append(x)





def dfs(num, depth):

    if c[num] != -1:

        return

    else:

        c[num] = depth

    for i in t[num]:

        dfs(i, depth)





cnt = 0

for i in range(n):

    if c[i] == -1:

        cnt += 1

        dfs(i, cnt)



print(cnt)

import sys

sys.setrecursionlimit(10**6)
n, m = list(map(int, input().split()))
t = [[] for i in range(n)]
c = [-1 for i in range(n)]
for i in range(m):
    x, y, z = list(map(int, input().split()))
    x -= 1
    y -= 1
    t[x].append(y)
    t[y].append(x)


def dfs(num, depth):
    if c[num] != -1:
        return
    else:
        c[num] = depth
    for i in t[num]:
        dfs(i, depth)


cnt = 0
for i in range(n):
    if c[i] == -1:
        cnt += 1
        dfs(i, cnt)
print((max(c)))

import sys

sys.setrecursionlimit(10**6)
n, m = list(map(int, input().split()))
t = [[] for i in range(n)]
c = [-1 for i in range(n)]
for line in sys.stdin:
    x, y, z = list(map(int, line.split()))
    x -= 1
    y -= 1
    t[x].append(y)
    t[y].append(x)


def dfs(num, depth):
    if c[num] != -1:
        return
    else:
        c[num] = depth
    for i in t[num]:
        dfs(i, depth)


cnt = 0
for i in range(n):
    if c[i] == -1:
        cnt += 1
        dfs(i, cnt)
print(cnt)

-for i in range(m): -    x, y, z = list(map(int, input().split())) +for line in sys.stdin: +    x, y, z = list(map(int, line.split())) -print((max(c))) +print(cnt)