from collections import deque



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

xyz = {i:[] for i in range(1, n+1)}

for _ in range(m):

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

    xyz[x].append((x, y, z))

    xyz[y].append((y, x, z))



connects = [0]*(n+1)

group = 1

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

    if connects[i] > 0:

        continue

    if len(xyz[i]) == 0:

        connects[i] = group

        group += 1

        continue



    que = deque(xyz[i])

    connects[i] = group

    while len(que) > 0:

        x, y, z = que.popleft()

        connects[y] = group

        for xn, yn, zn in xyz[y]:

            if connects[yn] > 0:

                pass

            else:

                que.append((xn, yn, zn))

    group += 1

    

# print(connects)

print((max(connects)))

from collections import deque



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

xyz = []

for _ in range(m):

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

    xyz.append((x, y, z))





uf = [-1]*(n+1)

def find(i):

    if uf[i] < 0:

        return i

    else:

        uf[i] = find(uf[i])

        return uf[i]



for x, y, z in xyz:

    px, py = find(x), find(y)

    

    if px != py:

        px, py = (px, py) if uf[py] < uf[px] else (px, py)

        uf[px] += uf[py]

        uf[py] = px



# print(uf)

ans = sum([1 for i in range(1, n+1) if uf[i] < 0])

print(ans)

from collections import deque

n, m = list(map(int, input().split()))
xyz = {i: [] for i in range(1, n + 1)}
for _ in range(m):
    x, y, z = list(map(int, input().split()))
    xyz[x].append((x, y, z))
    xyz[y].append((y, x, z))
connects = [0] * (n + 1)
group = 1
for i in range(1, n + 1):
    if connects[i] > 0:
        continue
    if len(xyz[i]) == 0:
        connects[i] = group
        group += 1
        continue
    que = deque(xyz[i])
    connects[i] = group
    while len(que) > 0:
        x, y, z = que.popleft()
        connects[y] = group
        for xn, yn, zn in xyz[y]:
            if connects[yn] > 0:
                pass
            else:
                que.append((xn, yn, zn))
    group += 1
# print(connects)
print((max(connects)))

from collections import deque

n, m = list(map(int, input().split()))
xyz = []
for _ in range(m):
    x, y, z = list(map(int, input().split()))
    xyz.append((x, y, z))
uf = [-1] * (n + 1)


def find(i):
    if uf[i] < 0:
        return i
    else:
        uf[i] = find(uf[i])
        return uf[i]


for x, y, z in xyz:
    px, py = find(x), find(y)
    if px != py:
        px, py = (px, py) if uf[py] < uf[px] else (px, py)
        uf[px] += uf[py]
        uf[py] = px
# print(uf)
ans = sum([1 for i in range(1, n + 1) if uf[i] < 0])
print(ans)

-xyz = {i: [] for i in range(1, n + 1)} +xyz = [] -    xyz[x].append((x, y, z)) -    xyz[y].append((y, x, z)) -connects = [0] * (n + 1) -group = 1 -for i in range(1, n + 1): -    if connects[i] > 0: -        continue -    if len(xyz[i]) == 0: -        connects[i] = group -        group += 1 -        continue -    que = deque(xyz[i]) -    connects[i] = group -    while len(que) > 0: -        x, y, z = que.popleft() -        connects[y] = group -        for xn, yn, zn in xyz[y]: -            if connects[yn] > 0: -                pass -            else: -                que.append((xn, yn, zn)) -    group += 1 -# print(connects) -print((max(connects))) +    xyz.append((x, y, z)) +uf = [-1] * (n + 1) + + +def find(i): +    if uf[i] < 0: +        return i +    else: +        uf[i] = find(uf[i]) +        return uf[i] + + +for x, y, z in xyz: +    px, py = find(x), find(y) +    if px != py: +        px, py = (px, py) if uf[py] < uf[px] else (px, py) +        uf[px] += uf[py] +        uf[py] = px +# print(uf) +ans = sum([1 for i in range(1, n + 1) if uf[i] < 0]) +print(ans)