from sys import setrecursionlimit, exit
setrecursionlimit(1000000000)

from collections import Counter

def main():
    n, m = map(int, input().split())
    par = [i for i in range(n)]
    size = [1] * n

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

    def same(x, y):
        return root(x) == root(y)

    def unite(x, y):
        x = root(x)
        y = root(y)
        if x == y:
            return
        par[x] = y
        size[y] += size[x]
    
    for _ in range(m):
        x, y, z = map(int, input().split())
        unite(x - 1, y - 1)
    for i in range(n):
        root(i)
    print(len(Counter(par)))

main() from sys import setrecursionlimit, exit setrecursionlimit(1000000000) setrecursionlimit 1000000000 from collections import Counter def main():
    n, m = map(int, input().split())
    par = [i for i in range(n)]
    size = [1] * n

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

    def same(x, y):
        return root(x) == root(y)

    def unite(x, y):
        x = root(x)
        y = root(y)
        if x == y:
            return
        par[x] = y
        size[y] += size[x]
    
    for _ in range(m):
        x, y, z = map(int, input().split())
        unite(x - 1, y - 1)
    for i in range(n):
        root(i)
    print(len(Counter(par))) main 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 par = [i for i in range(n)] par [i for i in range(n)] size = [1] * n size [1] * n [1] 1 n def root(x):
        if par[x] == x:
            return x
        else:
            par[x] = root(par[x])
            return par[x]

     root if par[x] == x:
            return x
        else:
            par[x] = root(par[x])
            return par[x]

     par[x] == x par[x] par x x return x x par[x] = root(par[x]) par[x] par x root(par[x]) root par[x] par x return par[x] par[x] par x x x def same(x, y):
        return root(x) == root(y)

     same return root(x) == root(y) root(x) == root(y) root(x) root x root(y) root y x x y y def unite(x, y):
        x = root(x)
        y = root(y)
        if x == y:
            return
        par[x] = y
        size[y] += size[x]
    
     unite x = root(x) x root(x) root x y = root(y) y root(y) root y if x == y:
            return
         x == y x y return par[x] = y par[x] par x y size[y] += size[x] size[y] size y size[x] size x x x y y 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 for i in range(n):
        root(i)
     i range(n) range n root(i) root i print(len(Counter(par))) print len(Counter(par)) len Counter(par) Counter par main() main def main():
    n, m = map(int, input().split())
    par = [i for i in range(n)]
    size = [1] * n

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

    def same(x, y):
        return root(x) == root(y)

    def unite(x, y):
        x = root(x)
        y = root(y)
        if x == y:
            return
        par[x] = y
        size[y] += size[x]
    
    for _ in range(m):
        x, y, z = map(int, input().split())
        unite(x - 1, y - 1)
    for i in range(n):
        root(i)
    print(len(Counter(par))) def main():
    n, m = map(int, input().split())
    par = [i for i in range(n)]
    size = [1] * n

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

    def same(x, y):
        return root(x) == root(y)

    def unite(x, y):
        x = root(x)
        y = root(y)
        if x == y:
            return
        par[x] = y
        size[y] += size[x]
    
    for _ in range(m):
        x, y, z = map(int, input().split())
        unite(x - 1, y - 1)
    for i in range(n):
        root(i)
    print(len(Counter(par))) main
from sys import setrecursionlimit, exit
setrecursionlimit(1000000000)

from collections import Counter

def main():
    n, m = map(int, input().split())
    par = [i for i in range(n)]
    size = [1] * n

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

    def same(x, y):
        return root(x) == root(y)

    def unite(x, y):
        x = root(x)
        y = root(y)
        if x == y:
            return
        par[x] = y
        size[y] += size[x]
    
    for _ in range(m):
        x, y, z = map(int, input().split())
        unite(x - 1, y - 1)
    for i in range(n):
        root(i)
    print(len(Counter(par)))

main()