import sys, collections

stdin = sys.stdin
n, m = map(int, stdin.readline().split())

par = [i for i in range(n)]
size = [1] * n  # size of tree
rank = [1] * n  # distance from parent


def find(x, par):
    if par[x] == x:
        return x
    else:
        return find(par[x], par)


def unite(x, y):
    x = find(x, par)
    y = find(y, par)

    if x != y:
        # xとyの属している集合が異なる時
        if rank[x] < rank[y]:
            par[x] = y
            size[y] += size[x]
        else:
            par[y] = x
            size[x] += size[y]
            if rank[x] == rank[y]:
                rank[x] += 1


for _ in range(m):
    x, y, z = map(int, stdin.readline().split())
    unite(x - 1, y - 1)
    
ans = set()
for i in range(n):
    ans.add(find(i, par))
print(len(ans)) import sys, collections sys collections stdin = sys.stdin stdin sys.stdin sys stdin n, m = map(int, stdin.readline().split()) n map(int, stdin.readline().split()) map int stdin.readline().split() stdin.readline().split stdin.readline() stdin.readline stdin readline split m i for i in range(n) for i in range(n) i range(n) range n for i in range(n) i par = [i for i in range(n)] par [i for i in range(n)] size = [1] * n size [1] * n [1] 1 n rank = [1] * n rank [1] * n [1] 1 n def find(x, par):
    if par[x] == x:
        return x
    else:
        return find(par[x], par) find if par[x] == x:
        return x
    else:
        return find(par[x], par) par[x] == x par[x] par x x return x x return find(par[x], par) find(par[x], par) find par[x] par x par x x par par def unite(x, y):
    x = find(x, par)
    y = find(y, par)

    if x != y:
        # xとyの属している集合が異なる時
        if rank[x] < rank[y]:
            par[x] = y
            size[y] += size[x]
        else:
            par[y] = x
            size[x] += size[y]
            if rank[x] == rank[y]:
                rank[x] += 1 unite x = find(x, par) x find(x, par) find x par y = find(y, par) y find(y, par) find y par if x != y:
        # xとyの属している集合が異なる時
        if rank[x] < rank[y]:
            par[x] = y
            size[y] += size[x]
        else:
            par[y] = x
            size[x] += size[y]
            if rank[x] == rank[y]:
                rank[x] += 1 x != y x y if rank[x] < rank[y]:
            par[x] = y
            size[y] += size[x]
        else:
            par[y] = x
            size[x] += size[y]
            if rank[x] == rank[y]:
                rank[x] += 1 rank[x] < rank[y] rank[x] rank x rank[y] rank y par[x] = y par[x] par x y size[y] += size[x] size[y] size y size[x] size x par[y] = x par[y] par y x size[x] += size[y] size[x] size x size[y] size y if rank[x] == rank[y]:
                rank[x] += 1 rank[x] == rank[y] rank[x] rank x rank[y] rank y rank[x] += 1 rank[x] rank x 1 x x y y for _ in range(m):
    x, y, z = map(int, stdin.readline().split())
    unite(x - 1, y - 1)
     _ range(m) range m x, y, z = map(int, stdin.readline().split()) x map(int, stdin.readline().split()) map int stdin.readline().split() stdin.readline().split stdin.readline() stdin.readline stdin readline split y z unite(x - 1, y - 1) unite x - 1 x 1 y - 1 y 1 ans = set() ans set() set for i in range(n):
    ans.add(find(i, par)) i range(n) range n ans.add(find(i, par)) ans.add ans add find(i, par) find i par print(len(ans)) print len(ans) len ans size = [1] * n [1] * n size def find(x, par):
    if par[x] == x:
        return x
    else:
        return find(par[x], par) def find(x, par):
    if par[x] == x:
        return x
    else:
        return find(par[x], par) find par = [i for i in range(n)] [i for i in range(n)] par rank = [1] * n [1] * n rank n, m = map(int, stdin.readline().split()) map(int, stdin.readline().split()) n z = map(int, stdin.readline().split()) map(int, stdin.readline().split()) z ans = set() set() ans m = map(int, stdin.readline().split()) map(int, stdin.readline().split()) m def unite(x, y):
    x = find(x, par)
    y = find(y, par)

    if x != y:
        # xとyの属している集合が異なる時
        if rank[x] < rank[y]:
            par[x] = y
            size[y] += size[x]
        else:
            par[y] = x
            size[x] += size[y]
            if rank[x] == rank[y]:
                rank[x] += 1 def unite(x, y):
    x = find(x, par)
    y = find(y, par)

    if x != y:
        # xとyの属している集合が異なる時
        if rank[x] < rank[y]:
            par[x] = y
            size[y] += size[x]
        else:
            par[y] = x
            size[x] += size[y]
            if rank[x] == rank[y]:
                rank[x] += 1 unite stdin = sys.stdin sys.stdin stdin x, y, z = map(int, stdin.readline().split()) map(int, stdin.readline().split()) x y, z = map(int, stdin.readline().split()) map(int, stdin.readline().split()) y
import sys, collections

stdin = sys.stdin
n, m = map(int, stdin.readline().split())

par = [i for i in range(n)]
size = [1] * n  # size of tree
rank = [1] * n  # distance from parent


def find(x, par):
    if par[x] == x:
        return x
    else:
        return find(par[x], par)


def unite(x, y):
    x = find(x, par)
    y = find(y, par)

    if x != y:
        # xとyの属している集合が異なる時
        if rank[x] < rank[y]:
            par[x] = y
            size[y] += size[x]
        else:
            par[y] = x
            size[x] += size[y]
            if rank[x] == rank[y]:
                rank[x] += 1


for _ in range(m):
    x, y, z = map(int, stdin.readline().split())
    unite(x - 1, y - 1)
    
ans = set()
for i in range(n):
    ans.add(find(i, par))
print(len(ans))