import sys

class UFT: #Union-find tree class
    def __init__(self, N): 
        self.tree = [int(i) for i in range(N)] 
        self.rank = [0 for i in range(N)]

    def find(self, a):
        if self.tree[a] == a: return a
        else:
            self.tree[a] = self.find(self.tree[a])
            return self.tree[a]

    def unite(self, a, b):
        a = self.find(a)
        b = self.find(b)
        if a == b: return
        if self.rank[a] < self.rank[b]: self.tree[a] = b
        else:
            self.tree[b] = a
            if self.rank[a] == self.rank[b]: self.rank[a] += 1

def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    parent = UFT(N)
    for i in range(M):
        x, y, z = map(int, input().split())
        parent.unite(x-1, y-1)
    for i in range(N):
        parent.find(i)

    print(len(set(parent.tree)))
    
    return 0

if __name__ == "__main__":
    solve() import sys sys class UFT: #Union-find tree class
    def __init__(self, N): 
        self.tree = [int(i) for i in range(N)] 
        self.rank = [0 for i in range(N)]

    def find(self, a):
        if self.tree[a] == a: return a
        else:
            self.tree[a] = self.find(self.tree[a])
            return self.tree[a]

    def unite(self, a, b):
        a = self.find(a)
        b = self.find(b)
        if a == b: return
        if self.rank[a] < self.rank[b]: self.tree[a] = b
        else:
            self.tree[b] = a
            if self.rank[a] == self.rank[b]: self.rank[a] += 1 UFT def __init__(self, N): 
        self.tree = [int(i) for i in range(N)] 
        self.rank = [0 for i in range(N)]

     __init__ int(i) for i in range(N) for i in range(N) i range(N) range N for i in range(N) int(i) int i self.tree = [int(i) for i in range(N)] self.tree self tree [int(i) for i in range(N)] 0 for i in range(N) for i in range(N) i range(N) range N for i in range(N) 0 self.rank = [0 for i in range(N)] self.rank self rank [0 for i in range(N)] self self N N def find(self, a):
        if self.tree[a] == a: return a
        else:
            self.tree[a] = self.find(self.tree[a])
            return self.tree[a]

     find if self.tree[a] == a: return a
        else:
            self.tree[a] = self.find(self.tree[a])
            return self.tree[a]

     self.tree[a] == a self.tree[a] self.tree self tree a a self.tree[a] = self.find(self.tree[a]) self.tree[a] self.tree self tree a self.find(self.tree[a]) self.find self find self.tree[a] self.tree self tree a return self.tree[a] self.tree[a] self.tree self tree a self self a a def unite(self, a, b):
        a = self.find(a)
        b = self.find(b)
        if a == b: return
        if self.rank[a] < self.rank[b]: self.tree[a] = b
        else:
            self.tree[b] = a
            if self.rank[a] == self.rank[b]: self.rank[a] += 1 unite a = self.find(a) a self.find(a) self.find self find a b = self.find(b) b self.find(b) self.find self find b if a == b: return
         a == b a b if self.rank[a] < self.rank[b]: self.tree[a] = b
        else:
            self.tree[b] = a
            if self.rank[a] == self.rank[b]: self.rank[a] += 1 self.rank[a] < self.rank[b] self.rank[a] self.rank self rank a self.rank[b] self.rank self rank b self.tree[b] = a self.tree[b] self.tree self tree b a if self.rank[a] == self.rank[b]: self. self.rank[a] == self.rank[b] self.rank[a] self.rank self rank a self.rank[b] self.rank self rank b self self a a b b def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    parent = UFT(N)
    for i in range(M):
        x, y, z = map(int, input().split())
        parent.unite(x-1, y-1)
    for i in range(N):
        parent.find(i)

    print(len(set(parent.tree)))
    
    return 0 solve input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M parent = UFT(N) parent UFT(N) UFT N for i in range(M):
        x, y, z = map(int, input().split())
        parent.unite(x-1, y-1)
     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 parent.unite(x-1, y-1) parent.unite parent unite x-1 x 1 y-1 y 1 for i in range(N):
        parent.find(i)

     i range(N) range N parent.find(i) parent.find parent find i print(len(set(parent.tree))) print len(set(parent.tree)) len set(parent.tree) set parent.tree parent tree return 0 0 if __name__ == "__main__":
    solve() __name__ == "__main__" __name__ "__main__" solve() solve class UFT: #Union-find tree class
    def __init__(self, N): 
        self.tree = [int(i) for i in range(N)] 
        self.rank = [0 for i in range(N)]

    def find(self, a):
        if self.tree[a] == a: return a
        else:
            self.tree[a] = self.find(self.tree[a])
            return self.tree[a]

    def unite(self, a, b):
        a = self.find(a)
        b = self.find(b)
        if a == b: return
        if self.rank[a] < self.rank[b]: self.tree[a] = b
        else:
            self.tree[b] = a
            if self.rank[a] == self.rank[b]: self.rank[a] += 1 class UFT: #Union-find tree class
    def __init__(self, N): 
        self.tree = [int(i) for i in range(N)] 
        self.rank = [0 for i in range(N)]

    def find(self, a):
        if self.tree[a] == a: return a
        else:
            self.tree[a] = self.find(self.tree[a])
            return self.tree[a]

    def unite(self, a, b):
        a = self.find(a)
        b = self.find(b)
        if a == b: return
        if self.rank[a] < self.rank[b]: self.tree[a] = b
        else:
            self.tree[b] = a
            if self.rank[a] == self.rank[b]: self.rank[a] += 1 UFT def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    parent = UFT(N)
    for i in range(M):
        x, y, z = map(int, input().split())
        parent.unite(x-1, y-1)
    for i in range(N):
        parent.find(i)

    print(len(set(parent.tree)))
    
    return 0 def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    parent = UFT(N)
    for i in range(M):
        x, y, z = map(int, input().split())
        parent.unite(x-1, y-1)
    for i in range(N):
        parent.find(i)

    print(len(set(parent.tree)))
    
    return 0 solve
import sys

class UFT: #Union-find tree class
    def __init__(self, N): 
        self.tree = [int(i) for i in range(N)] 
        self.rank = [0 for i in range(N)]

    def find(self, a):
        if self.tree[a] == a: return a
        else:
            self.tree[a] = self.find(self.tree[a])
            return self.tree[a]

    def unite(self, a, b):
        a = self.find(a)
        b = self.find(b)
        if a == b: return
        if self.rank[a] < self.rank[b]: self.tree[a] = b
        else:
            self.tree[b] = a
            if self.rank[a] == self.rank[b]: self.rank[a] += 1

def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    parent = UFT(N)
    for i in range(M):
        x, y, z = map(int, input().split())
        parent.unite(x-1, y-1)
    for i in range(N):
        parent.find(i)

    print(len(set(parent.tree)))
    
    return 0

if __name__ == "__main__":
    solve()