import collections
# from collections import deque
# from fractions import gcd # >=Python3.5 # lcm = (a*b)//gcd(a,b)
# from math import gcd # <Python3.5
# from math import sqrt

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

n,m = map(int,input().split())
uf = UnionFind(n)

for i in range(m):
    x,y,z = map(int,input().split())
    uf.union(x,y)

# cnt = collections.Counter(uf.par)

# print(cnt)

# print(len(set(cnt))-1)

tank = set([])
for i in range(1,n+1):
    tank.add(uf.find(i))
print(len(tank)) import collections collections class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y) UnionFind def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
     __init__ 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 self.par = [i for i in range(n+1)] self.par self par [i for i in range(n+1)] self.rank = [0] * (n+1) self.rank self rank [0] * (n+1) [0] 0 n+1 n 1 self self n n def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
     find if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
     self.par[x] == x self.par[x] self.par self par x x return x x self.par[x] = self.find(self.par[x]) self.par[x] self.par self par x self.find(self.par[x]) self.find self find self.par[x] self.par self par x return self.par[x] self.par[x] self.par self par x self self x x def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
     union x = self.find(x) x self.find(x) self.find self find x y = self.find(y) y self.find(y) self.find self find y if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
     self.rank[x] < self.rank[y] self.rank[x] self.rank self rank x self.rank[y] self.rank self rank y self.par[x] = y self.par[x] self.par self par x y self.par[y] = x self.par[y] self.par self par y x if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
     self.rank[x] == self.rank[y] self.rank[x] self.rank self rank x self.rank[y] self.rank self rank y self.rank[x] += 1 self.rank[x] self.rank self rank x 1 self self x x y y def same_check(self, x, y):
        return self.find(x) == self.find(y) same_check return self.find(x) == self.find(y) self.find(x) == self.find(y) self.find(x) self.find self find x self.find(y) self.find self find y self self x x y y n,m = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m uf = UnionFind(n) uf UnionFind(n) UnionFind n for i in range(m):
    x,y,z = map(int,input().split())
    uf.union(x,y)

# cnt = collections.Counter(uf.par)

# print(cnt)

# print(len(set(cnt))-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 uf.union(x,y) uf.union uf union x y tank = set([]) tank set([]) set [] for i in range(1,n+1):
    tank.add(uf.find(i)) i range(1,n+1) range 1 n+1 n 1 tank.add(uf.find(i)) tank.add tank add uf.find(i) uf.find uf find i print(len(tank)) print len(tank) len tank class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y) class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y) UnionFind uf = UnionFind(n) UnionFind(n) uf x,y,z = map(int,input().split()) map(int,input().split()) x y,z = map(int,input().split()) map(int,input().split()) y tank = set([]) set([]) tank n,m = map(int,input().split()) map(int,input().split()) n m = map(int,input().split()) map(int,input().split()) m z = map(int,input().split()) map(int,input().split()) z
import collections
# from collections import deque
# from fractions import gcd # >=Python3.5 # lcm = (a*b)//gcd(a,b)
# from math import gcd # <Python3.5
# from math import sqrt

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

n,m = map(int,input().split())
uf = UnionFind(n)

for i in range(m):
    x,y,z = map(int,input().split())
    uf.union(x,y)

# cnt = collections.Counter(uf.par)

# print(cnt)

# print(len(set(cnt))-1)

tank = set([])
for i in range(1,n+1):
    tank.add(uf.find(i))
print(len(tank))