def get_root(s):
    if s != root[s]:
        root[s] = get_root(root[s])
        return root[s]
    return s

def unite(s, t):
    global ans
    root_s = get_root(s)
    root_t = get_root(t)
    if not root_s == root_t:
        ans -= 1
        if rank[s] == rank[t]:
            root[root_t] = root_s
            rank[root_s] += 1
        elif rank[s] > rank[t]:
            root[root_t] = root_s
        else:
            root[root_s] = root_t

n, m = map(int, input().split())
root = [i for i in range(n)]
rank = [1 for _ in range(n)]
ans = n
for _ in range(m):
    x, y, z = map(int, input().split())
    unite(x - 1, y - 1)
print(ans) def get_root(s):
    if s != root[s]:
        root[s] = get_root(root[s])
        return root[s]
    return s get_root if s != root[s]:
        root[s] = get_root(root[s])
        return root[s]
     s != root[s] s root[s] root s root[s] = get_root(root[s]) root[s] root s get_root(root[s]) get_root root[s] root s return root[s] root[s] root s return s s s s def unite(s, t):
    global ans
    root_s = get_root(s)
    root_t = get_root(t)
    if not root_s == root_t:
        ans -= 1
        if rank[s] == rank[t]:
            root[root_t] = root_s
            rank[root_s] += 1
        elif rank[s] > rank[t]:
            root[root_t] = root_s
        else:
            root[root_s] = root_t unite global ans root_s = get_root(s) root_s get_root(s) get_root s root_t = get_root(t) root_t get_root(t) get_root t if not root_s == root_t:
        ans -= 1
        if rank[s] == rank[t]:
            root[root_t] = root_s
            rank[root_s] += 1
        elif rank[s] > rank[t]:
            root[root_t] = root_s
        else:
            root[root_s] = root_t not root_s == root_t root_s == root_t root_s root_t ans -= 1 ans 1 if rank[s] == rank[t]:
            root[root_t] = root_s
            rank[root_s] += 1
        elif rank[s] > rank[t]:
            root[root_t] = root_s
        else:
            root[root_s] = root_t rank[s] == rank[t] rank[s] rank s rank[t] rank t root[root_t] = root_s root[root_t] root root_t root_s rank[root_s] += 1 rank[root_s] rank root_s 1 elif rank[s] > rank[t]:
            root[root_t] = root_s
         rank[s] > rank[t] rank[s] rank s rank[t] rank t root[root_t] = root_s root[root_t] root root_t root_s root[root_s] = root_t root[root_s] root root_s root_t s s t t 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) for i in range(n) i range(n) range n for i in range(n) i root = [i for i in range(n)] root [i for i in range(n)] 1 for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) 1 rank = [1 for _ in range(n)] rank [1 for _ in range(n)] ans = n ans n for _ in range(m):
    x, y, z = map(int, input().split())
    unite(x - 1, y - 1) _ 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 unite(x - 1, y - 1) unite x - 1 x 1 y - 1 y 1 print(ans) print ans root = [i for i in range(n)] [i for i in range(n)] root y, z = map(int, input().split()) map(int, input().split()) y def unite(s, t):
    global ans
    root_s = get_root(s)
    root_t = get_root(t)
    if not root_s == root_t:
        ans -= 1
        if rank[s] == rank[t]:
            root[root_t] = root_s
            rank[root_s] += 1
        elif rank[s] > rank[t]:
            root[root_t] = root_s
        else:
            root[root_s] = root_t def unite(s, t):
    global ans
    root_s = get_root(s)
    root_t = get_root(t)
    if not root_s == root_t:
        ans -= 1
        if rank[s] == rank[t]:
            root[root_t] = root_s
            rank[root_s] += 1
        elif rank[s] > rank[t]:
            root[root_t] = root_s
        else:
            root[root_s] = root_t unite z = map(int, input().split()) map(int, input().split()) z x, y, z = map(int, input().split()) map(int, input().split()) x n, m = map(int, input().split()) map(int, input().split()) n m = map(int, input().split()) map(int, input().split()) m def get_root(s):
    if s != root[s]:
        root[s] = get_root(root[s])
        return root[s]
    return s def get_root(s):
    if s != root[s]:
        root[s] = get_root(root[s])
        return root[s]
    return s get_root ans = n n ans rank = [1 for _ in range(n)] [1 for _ in range(n)] rank
def get_root(s):
    if s != root[s]:
        root[s] = get_root(root[s])
        return root[s]
    return s

def unite(s, t):
    global ans
    root_s = get_root(s)
    root_t = get_root(t)
    if not root_s == root_t:
        ans -= 1
        if rank[s] == rank[t]:
            root[root_t] = root_s
            rank[root_s] += 1
        elif rank[s] > rank[t]:
            root[root_t] = root_s
        else:
            root[root_s] = root_t

n, m = map(int, input().split())
root = [i for i in range(n)]
rank = [1 for _ in range(n)]
ans = n
for _ in range(m):
    x, y, z = map(int, input().split())
    unite(x - 1, y - 1)
print(ans)