class Node:

    def __init__(self, val):

        self.num = val

        self.val = val

        self.is_parent = True

        self.parent = None



def root(node):

    depth = 0

    while node.parent != None:

        node = node.parent

        depth += 1

    return node, depth



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



roots = [Node(i) for i in range(N)]

count = N



for i in range(M):

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

    x = roots[x-1]

    y = roots[y-1]

    if x.is_parent and y.is_parent:

            y.is_parent = False

            y.parent = x

            count -= 1

    else:

        root_x, depth_x = root(x)

        root_y, depth_y = root(y)

        if root_x != root_y:

            if depth_x >= depth_y:

                root_y.is_parent = False

                root_y.parent = root_x

                count -= 1

            else:

                root_x.is_parent = False

                root_x.parent = root_y

                count -= 1



print(count)

class Node:

    def __init__(self):

        self.is_parent = True

        self.parent = None



def root(node):

    depth = 0

    while node.parent != None:

        node = node.parent

        depth += 1

    return node, depth



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



roots = [Node() for i in range(N)]

count = N



for i in range(M):

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

    x = roots[x-1]

    y = roots[y-1]

    if x.is_parent and y.is_parent:

            y.is_parent = False

            y.parent = x

            count -= 1

    else:

        root_x, depth_x = root(x)

        root_y, depth_y = root(y)

        if root_x != root_y:

            if depth_x >= depth_y:

                root_y.is_parent = False

                root_y.parent = root_x

                count -= 1

            else:

                root_x.is_parent = False

                root_x.parent = root_y

                count -= 1



print(count)

class Node:
    def __init__(self, val):
        self.num = val
        self.val = val
        self.is_parent = True
        self.parent = None


def root(node):
    depth = 0
    while node.parent != None:
        node = node.parent
        depth += 1
    return node, depth


N, M = list(map(int, input().split()))
roots = [Node(i) for i in range(N)]
count = N
for i in range(M):
    x, y, z = list(map(int, input().split()))
    x = roots[x - 1]
    y = roots[y - 1]
    if x.is_parent and y.is_parent:
        y.is_parent = False
        y.parent = x
        count -= 1
    else:
        root_x, depth_x = root(x)
        root_y, depth_y = root(y)
        if root_x != root_y:
            if depth_x >= depth_y:
                root_y.is_parent = False
                root_y.parent = root_x
                count -= 1
            else:
                root_x.is_parent = False
                root_x.parent = root_y
                count -= 1
print(count)

class Node:
    def __init__(self):
        self.is_parent = True
        self.parent = None


def root(node):
    depth = 0
    while node.parent != None:
        node = node.parent
        depth += 1
    return node, depth


N, M = list(map(int, input().split()))
roots = [Node() for i in range(N)]
count = N
for i in range(M):
    x, y, z = list(map(int, input().split()))
    x = roots[x - 1]
    y = roots[y - 1]
    if x.is_parent and y.is_parent:
        y.is_parent = False
        y.parent = x
        count -= 1
    else:
        root_x, depth_x = root(x)
        root_y, depth_y = root(y)
        if root_x != root_y:
            if depth_x >= depth_y:
                root_y.is_parent = False
                root_y.parent = root_x
                count -= 1
            else:
                root_x.is_parent = False
                root_x.parent = root_y
                count -= 1
print(count)

-    def __init__(self, val): -        self.num = val -        self.val = val +    def __init__(self): -roots = [Node(i) for i in range(N)] +roots = [Node() for i in range(N)]