class UnionFind:
    def __init__(self,n):
        self.n=n
        self.parents=[-1]*n
        self.rank=[0]*n

    def find(self,x):
        if self.parents[x]<0:
            return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]

    def union(self,x,y):
        x=self.find(x)
        y=self.find(y)

        if x==y:
            return 

        if self.rank[x]<self.rank[y]:
            self.parents[y]+=self.parents[x]
            self.parents[x]=y
        else:
            self.parents[x]+=self.parents[y]
            self.parents[y]=x

            if self.rank[x]==self.rank[y]:
                self.rank[x]+=1

    def are_same(self,x,y):
        return self.find(x)==self.find(y)

    def element_count(self,x):
        x=self.find(x)
        return -self.parents[x]

    def group_count(self):
        count=0
        for e in self.parents:
            if e<0: count+=1
        return count

from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n,m=map(int,readline().split())
    uf=UnionFind(n)
    for i in range(m):
        x,y,z=map(int,readline().split())
        x-=1
        y-=1
        uf.union(x,y)
    print(uf.group_count())

if __name__=="__main__":
    main() class UnionFind:
    def __init__(self,n):
        self.n=n
        self.parents=[-1]*n
        self.rank=[0]*n

    def find(self,x):
        if self.parents[x]<0:
            return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]

    def union(self,x,y):
        x=self.find(x)
        y=self.find(y)

        if x==y:
            return 

        if self.rank[x]<self.rank[y]:
            self.parents[y]+=self.parents[x]
            self.parents[x]=y
        else:
            self.parents[x]+=self.parents[y]
            self.parents[y]=x

            if self.rank[x]==self.rank[y]:
                self.rank[x]+=1

    def are_same(self,x,y):
        return self.find(x)==self.find(y)

    def element_count(self,x):
        x=self.find(x)
        return -self.parents[x]

    def group_count(self):
        count=0
        for e in self.parents:
            if e<0: count+=1
        return count UnionFind def __init__(self,n):
        self.n=n
        self.parents=[-1]*n
        self.rank=[0]*n

     __init__ self.n=n self.n self n n self.parents=[-1]*n self.parents self parents [-1]*n [-1] -1 n self.rank=[0]*n self.rank self rank [0]*n [0] 0 n self self n n def find(self,x):
        if self.parents[x]<0:
            return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]

     find if self.parents[x]<0:
            return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]

     self.parents[x]<0 self.parents[x] self.parents self parents x 0 return x x self.parents[x]=self.find(self.parents[x]) self.parents[x] self.parents self parents x self.find(self.parents[x]) self.find self find self.parents[x] self.parents self parents x return self.parents[x] self.parents[x] self.parents self parents x self self x x def union(self,x,y):
        x=self.find(x)
        y=self.find(y)

        if x==y:
            return 

        if self.rank[x]<self.rank[y]:
            self.parents[y]+=self.parents[x]
            self.parents[x]=y
        else:
            self.parents[x]+=self.parents[y]
            self.parents[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 x==y:
            return 

         x==y x y return if self.rank[x]<self.rank[y]:
            self.parents[y]+=self.parents[x]
            self.parents[x]=y
        else:
            self.parents[x]+=self.parents[y]
            self.parents[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.parents[y]+=self.parents[x] self.parents[y] self.parents self parents y self.parents[x] self.parents self parents x self.parents[x]=y self.parents[x] self.parents self parents x y self.parents[x]+=self.parents[y] self.parents[x] self.parents self parents x self.parents[y] self.parents self parents y self.parents[y]=x self.parents[y] self.parents self parents 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 are_same(self,x,y):
        return self.find(x)==self.find(y)

     are_same 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 def element_count(self,x):
        x=self.find(x)
        return -self.parents[x]

     element_count x=self.find(x) x self.find(x) self.find self find x return -self.parents[x] -self.parents[x] self.parents[x] self.parents self parents x self self x x def group_count(self):
        count=0
        for e in self.parents:
            if e<0: count+=1
        return count group_count count=0 count 0 for e in self.parents:
            if e<0: count+=1
         e self.parents self parents if e<0: count+=1
         e<0 e 0 return count count self self from sys import stdin def main():
    #入力
    readline=stdin.readline
    n,m=map(int,readline().split())
    uf=UnionFind(n)
    for i in range(m):
        x,y,z=map(int,readline().split())
        x-=1
        y-=1
        uf.union(x,y)
    print(uf.group_count()) main readline=stdin.readline readline stdin.readline stdin readline n,m=map(int,readline().split()) n map(int,readline().split()) map int readline().split() ().split () readline split m uf=UnionFind(n) uf UnionFind(n) UnionFind n for i in range(m):
        x,y,z=map(int,readline().split())
        x-=1
        y-=1
        uf.union(x,y)
     i range(m) range m x,y,z=map(int,readline().split()) x map(int,readline().split()) map int readline().split() ().split () readline split y z x-=1 x 1 y-=1 y 1 uf.union(x,y) uf.union uf union x y print(uf.group_count()) print uf.group_count() uf.group_count uf group_count if __name__=="__main__":
    main() __name__=="__main__" __name__ "__main__" main() main class UnionFind:
    def __init__(self,n):
        self.n=n
        self.parents=[-1]*n
        self.rank=[0]*n

    def find(self,x):
        if self.parents[x]<0:
            return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]

    def union(self,x,y):
        x=self.find(x)
        y=self.find(y)

        if x==y:
            return 

        if self.rank[x]<self.rank[y]:
            self.parents[y]+=self.parents[x]
            self.parents[x]=y
        else:
            self.parents[x]+=self.parents[y]
            self.parents[y]=x

            if self.rank[x]==self.rank[y]:
                self.rank[x]+=1

    def are_same(self,x,y):
        return self.find(x)==self.find(y)

    def element_count(self,x):
        x=self.find(x)
        return -self.parents[x]

    def group_count(self):
        count=0
        for e in self.parents:
            if e<0: count+=1
        return count class UnionFind:
    def __init__(self,n):
        self.n=n
        self.parents=[-1]*n
        self.rank=[0]*n

    def find(self,x):
        if self.parents[x]<0:
            return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]

    def union(self,x,y):
        x=self.find(x)
        y=self.find(y)

        if x==y:
            return 

        if self.rank[x]<self.rank[y]:
            self.parents[y]+=self.parents[x]
            self.parents[x]=y
        else:
            self.parents[x]+=self.parents[y]
            self.parents[y]=x

            if self.rank[x]==self.rank[y]:
                self.rank[x]+=1

    def are_same(self,x,y):
        return self.find(x)==self.find(y)

    def element_count(self,x):
        x=self.find(x)
        return -self.parents[x]

    def group_count(self):
        count=0
        for e in self.parents:
            if e<0: count+=1
        return count UnionFind def main():
    #入力
    readline=stdin.readline
    n,m=map(int,readline().split())
    uf=UnionFind(n)
    for i in range(m):
        x,y,z=map(int,readline().split())
        x-=1
        y-=1
        uf.union(x,y)
    print(uf.group_count()) def main():
    #入力
    readline=stdin.readline
    n,m=map(int,readline().split())
    uf=UnionFind(n)
    for i in range(m):
        x,y,z=map(int,readline().split())
        x-=1
        y-=1
        uf.union(x,y)
    print(uf.group_count()) main
class UnionFind:
    def __init__(self,n):
        self.n=n
        self.parents=[-1]*n
        self.rank=[0]*n

    def find(self,x):
        if self.parents[x]<0:
            return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]

    def union(self,x,y):
        x=self.find(x)
        y=self.find(y)

        if x==y:
            return 

        if self.rank[x]<self.rank[y]:
            self.parents[y]+=self.parents[x]
            self.parents[x]=y
        else:
            self.parents[x]+=self.parents[y]
            self.parents[y]=x

            if self.rank[x]==self.rank[y]:
                self.rank[x]+=1

    def are_same(self,x,y):
        return self.find(x)==self.find(y)

    def element_count(self,x):
        x=self.find(x)
        return -self.parents[x]

    def group_count(self):
        count=0
        for e in self.parents:
            if e<0: count+=1
        return count

from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n,m=map(int,readline().split())
    uf=UnionFind(n)
    for i in range(m):
        x,y,z=map(int,readline().split())
        x-=1
        y-=1
        uf.union(x,y)
    print(uf.group_count())

if __name__=="__main__":
    main()