def find_base_label(lookup_table, label):
    base_label = label
    while lookup_table[base_label] != base_label:
        base_label = lookup_table[base_label]
    return base_label


def main():
    n, m = map(int, input().split())

    lookup_table = list(range(n))
    for _ in range(m):
        x, y, z = map(int, input().split())

        base_label_1 = find_base_label(lookup_table, x - 1)
        base_label_2 = find_base_label(lookup_table, y - 1)

        if base_label_1 < base_label_2:
            lookup_table[base_label_2] = base_label_1
        elif base_label_2 < base_label_1:
            lookup_table[base_label_1] = base_label_2

    for i in range(n):
        lookup_table[i] = lookup_table[lookup_table[i]]

    print(len(set(lookup_table)))


main() def find_base_label(lookup_table, label):
    base_label = label
    while lookup_table[base_label] != base_label:
        base_label = lookup_table[base_label]
    return base_label find_base_label base_label = label base_label label while lookup_table[base_label] != base_label:
        base_label = lookup_table[base_label]
     lookup_table[base_label] != base_label lookup_table[base_label] lookup_table base_label base_label base_label = lookup_table[base_label] base_label lookup_table[base_label] lookup_table base_label return base_label base_label lookup_table lookup_table label label def main():
    n, m = map(int, input().split())

    lookup_table = list(range(n))
    for _ in range(m):
        x, y, z = map(int, input().split())

        base_label_1 = find_base_label(lookup_table, x - 1)
        base_label_2 = find_base_label(lookup_table, y - 1)

        if base_label_1 < base_label_2:
            lookup_table[base_label_2] = base_label_1
        elif base_label_2 < base_label_1:
            lookup_table[base_label_1] = base_label_2

    for i in range(n):
        lookup_table[i] = lookup_table[lookup_table[i]]

    print(len(set(lookup_table))) main n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m lookup_table = list(range(n)) lookup_table list(range(n)) list range(n) range n for _ in range(m):
        x, y, z = map(int, input().split())

        base_label_1 = find_base_label(lookup_table, x - 1)
        base_label_2 = find_base_label(lookup_table, y - 1)

        if base_label_1 < base_label_2:
            lookup_table[base_label_2] = base_label_1
        elif base_label_2 < base_label_1:
            lookup_table[base_label_1] = base_label_2

     _ range(m) range m x, y, z = map(int, input().split()) x map(int, input().split()) map int input().split() ().split () input split y z base_label_1 = find_base_label(lookup_table, x - 1) base_label_1 find_base_label(lookup_table, x - 1) find_base_label lookup_table x - 1 x 1 base_label_2 = find_base_label(lookup_table, y - 1) base_label_2 find_base_label(lookup_table, y - 1) find_base_label lookup_table y - 1 y 1 if base_label_1 < base_label_2:
            lookup_table[base_label_2] = base_label_1
        elif base_label_2 < base_label_1:
            lookup_table[base_label_1] = base_label_2

     base_label_1 < base_label_2 base_label_1 base_label_2 lookup_table[base_label_2] = base_label_1 lookup_table[base_label_2] lookup_table base_label_2 base_label_1 elif base_label_2 < base_label_1:
            lookup_table[base_label_1] = base_label_2

     base_label_2 < base_label_1 base_label_2 base_label_1 lookup_table[base_label_1] = base_label_2 lookup_table[base_label_1] lookup_table base_label_1 base_label_2 for i in range(n):
        lookup_table[i] = lookup_table[lookup_table[i]]

     i range(n) range n lookup_table[i] = lookup_table[lookup_table[i]] lookup_table[i] lookup_table i lookup_table[lookup_table[i]] lookup_table lookup_table[i] lookup_table i print(len(set(lookup_table))) print len(set(lookup_table)) len set(lookup_table) set lookup_table main() main def find_base_label(lookup_table, label):
    base_label = label
    while lookup_table[base_label] != base_label:
        base_label = lookup_table[base_label]
    return base_label def find_base_label(lookup_table, label):
    base_label = label
    while lookup_table[base_label] != base_label:
        base_label = lookup_table[base_label]
    return base_label find_base_label def main():
    n, m = map(int, input().split())

    lookup_table = list(range(n))
    for _ in range(m):
        x, y, z = map(int, input().split())

        base_label_1 = find_base_label(lookup_table, x - 1)
        base_label_2 = find_base_label(lookup_table, y - 1)

        if base_label_1 < base_label_2:
            lookup_table[base_label_2] = base_label_1
        elif base_label_2 < base_label_1:
            lookup_table[base_label_1] = base_label_2

    for i in range(n):
        lookup_table[i] = lookup_table[lookup_table[i]]

    print(len(set(lookup_table))) def main():
    n, m = map(int, input().split())

    lookup_table = list(range(n))
    for _ in range(m):
        x, y, z = map(int, input().split())

        base_label_1 = find_base_label(lookup_table, x - 1)
        base_label_2 = find_base_label(lookup_table, y - 1)

        if base_label_1 < base_label_2:
            lookup_table[base_label_2] = base_label_1
        elif base_label_2 < base_label_1:
            lookup_table[base_label_1] = base_label_2

    for i in range(n):
        lookup_table[i] = lookup_table[lookup_table[i]]

    print(len(set(lookup_table))) main
def find_base_label(lookup_table, label):
    base_label = label
    while lookup_table[base_label] != base_label:
        base_label = lookup_table[base_label]
    return base_label


def main():
    n, m = map(int, input().split())

    lookup_table = list(range(n))
    for _ in range(m):
        x, y, z = map(int, input().split())

        base_label_1 = find_base_label(lookup_table, x - 1)
        base_label_2 = find_base_label(lookup_table, y - 1)

        if base_label_1 < base_label_2:
            lookup_table[base_label_2] = base_label_1
        elif base_label_2 < base_label_1:
            lookup_table[base_label_1] = base_label_2

    for i in range(n):
        lookup_table[i] = lookup_table[lookup_table[i]]

    print(len(set(lookup_table)))


main()
