n, m = map(int, input().split())
tree = [-i for i in range(n+1)]
rank = [1 for _i in range(n+1)]
def search_root(num, tree=tree):
    if tree[num] < 0:
        return num
    else:
        tree[num] = search_root(tree[num])
        return tree[num]

for _i in range(m):
    x, y, z = map(int, input().split())
    x, y = [search_root(x), search_root(y)]
    if x==y:
        continue
    else:
        if rank[x]<rank[y]:
            rank[y] += 1
            tree[x] = y
        else:
            rank[x] += 1
            tree[y] = x
print(sum(1 for i in tree if i<0)) n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m -i for i in range(n+1) for i in range(n+1) i range(n+1) range n+1 n 1 for i in range(n+1) -i i tree = [-i for i in range(n+1)] tree [-i for i in range(n+1)] 1 for _i in range(n+1) for _i in range(n+1) _i range(n+1) range n+1 n 1 for _i in range(n+1) 1 rank = [1 for _i in range(n+1)] rank [1 for _i in range(n+1)] def search_root(num, tree=tree):
    if tree[num] < 0:
        return num
    else:
        tree[num] = search_root(tree[num])
        return tree[num] search_root if tree[num] < 0:
        return num
    else:
        tree[num] = search_root(tree[num])
        return tree[num] tree[num] < 0 tree[num] tree num 0 return num num tree[num] = search_root(tree[num]) tree[num] tree num search_root(tree[num]) search_root tree[num] tree num return tree[num] tree[num] tree num num num tree=tree tree tree for _i in range(m):
    x, y, z = map(int, input().split())
    x, y = [search_root(x), search_root(y)]
    if x==y:
        continue
    else:
        if rank[x]<rank[y]:
            rank[y] += 1
            tree[x] = y
        else:
            rank[x] += 1
            tree[y] = x _i 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 x, y = [search_root(x), search_root(y)] x [search_root(x), search_root(y)] search_root(x) search_root x search_root(y) search_root y y if x==y:
        continue
    else:
        if rank[x]<rank[y]:
            rank[y] += 1
            tree[x] = y
        else:
            rank[x] += 1
            tree[y] = x x==y x y continue if rank[x]<rank[y]:
            rank[y] += 1
            tree[x] = y
        else:
            rank[x] += 1
            tree[y] = x rank[x]<rank[y] rank[x] rank x rank[y] rank y rank[y] += 1 rank[y] rank y 1 tree[x] = y tree[x] tree x y rank[x] += 1 rank[x] rank x 1 tree[y] = x tree[y] tree y x print(sum(1 for i in tree if i<0)) print sum(1 for i in tree if i<0) sum 1 m = map(int, input().split()) map(int, input().split()) m rank = [1 for _i in range(n+1)] [1 for _i in range(n+1)] rank def search_root(num, tree=tree):
    if tree[num] < 0:
        return num
    else:
        tree[num] = search_root(tree[num])
        return tree[num] def search_root(num, tree=tree):
    if tree[num] < 0:
        return num
    else:
        tree[num] = search_root(tree[num])
        return tree[num] search_root x, y = [search_root(x), search_root(y)] [search_root(x), search_root(y)] x x, y, z = map(int, input().split()) map(int, input().split()) x z = map(int, input().split()) map(int, input().split()) z y = [search_root(x), search_root(y)] [search_root(x), search_root(y)] y n, m = map(int, input().split()) map(int, input().split()) n tree = [-i for i in range(n+1)] [-i for i in range(n+1)] tree y, z = map(int, input().split()) map(int, input().split()) y
n, m = map(int, input().split())
tree = [-i for i in range(n+1)]
rank = [1 for _i in range(n+1)]
def search_root(num, tree=tree):
    if tree[num] < 0:
        return num
    else:
        tree[num] = search_root(tree[num])
        return tree[num]

for _i in range(m):
    x, y, z = map(int, input().split())
    x, y = [search_root(x), search_root(y)]
    if x==y:
        continue
    else:
        if rank[x]<rank[y]:
            rank[y] += 1
            tree[x] = y
        else:
            rank[x] += 1
            tree[y] = x
print(sum(1 for i in tree if i<0))