import sys
input = sys.stdin.readline
from collections import Counter


def read():
    N, M = map(int, input().strip().split())
    XYZ = []
    for i in range(M):
        x, y, z = map(int, input().strip().split())
        XYZ.append((x, y, z))
    return N, M, XYZ


class UnionFind():
    """Union-Find木の実装
    """

    def __init__(self, n):
        self.n = n
        self.parent = [x for x in range(n)]

    def find(self, x):
        """要素xが所属するグループを返す
        """
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def union(self, x, y):
        """要素x, yがそれぞれ所属するグループを併合する
        """
        x = self.find(x)
        y = self.find(y)
        if x > y:
            x, y = y, x
        self.parent[y] = x

    def parents(self):
        return [self.find(x) for x in range(self.n)]


def solve(N, M, XYZ):
    uf = UnionFind(N)
    for x, y, z in XYZ:
        uf.union(x-1, y-1)
    C = Counter(uf.parents())
    return len(C)


if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs)) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline from collections import Counter def read():
    N, M = map(int, input().strip().split())
    XYZ = []
    for i in range(M):
        x, y, z = map(int, input().strip().split())
        XYZ.append((x, y, z))
    return N, M, XYZ read N, M = map(int, input().strip().split()) N map(int, input().strip().split()) map int input().strip().split() ().strip().split ().strip() ().strip () input strip split M XYZ = [] XYZ [] for i in range(M):
        x, y, z = map(int, input().strip().split())
        XYZ.append((x, y, z))
     i range(M) range M x, y, z = map(int, input().strip().split()) x map(int, input().strip().split()) map int input().strip().split() ().strip().split ().strip() ().strip () input strip split y z XYZ.append((x, y, z)) XYZ.append XYZ append (x, y, z) x y z return N, M, XYZ return N, M, XYZ N M XYZ class UnionFind():
    """Union-Find木の実装
    """

    def __init__(self, n):
        self.n = n
        self.parent = [x for x in range(n)]

    def find(self, x):
        """要素xが所属するグループを返す
        """
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def union(self, x, y):
        """要素x, yがそれぞれ所属するグループを併合する
        """
        x = self.find(x)
        y = self.find(y)
        if x > y:
            x, y = y, x
        self.parent[y] = x

    def parents(self):
        return [self.find(x) for x in range(self.n)] UnionFind """Union-Find木の実装
    """ def __init__(self, n):
        self.n = n
        self.parent = [x for x in range(n)]

     __init__ self.n = n self.n self n n x for x in range(n) for x in range(n) x range(n) range n for x in range(n) x self.parent = [x for x in range(n)] self.parent self parent [x for x in range(n)] self self n n def find(self, x):
        """要素xが所属するグループを返す
        """
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

     find """要素xが所属するグループを返す
        """ if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

     self.parent[x] == x self.parent[x] self.parent self parent x x return x x self.parent[x] = self.find(self.parent[x]) self.parent[x] self.parent self parent x self.find(self.parent[x]) self.find self find self.parent[x] self.parent self parent x return self.parent[x] self.parent[x] self.parent self parent x self self x x def union(self, x, y):
        """要素x, yがそれぞれ所属するグループを併合する
        """
        x = self.find(x)
        y = self.find(y)
        if x > y:
            x, y = y, x
        self.parent[y] = x

     union """要素x, yがそれぞれ所属するグループを併合する
        """ 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:
            x, y = y, x
         x > y x y x, y = y, x x y y x self.parent[y] = x self.parent[y] self.parent self parent y x self self x x y y def parents(self):
        return [self.find(x) for x in range(self.n)] parents self.find(x) for x in range(self.n) for x in range(self.n) x range(self.n) range self.n self n for x in range(self.n) self.find(x) self.find self find x return [self.find(x) for x in range(self.n)] [self.find(x) for x in range(self.n)] self self def solve(N, M, XYZ):
    uf = UnionFind(N)
    for x, y, z in XYZ:
        uf.union(x-1, y-1)
    C = Counter(uf.parents())
    return len(C) solve uf = UnionFind(N) uf UnionFind(N) UnionFind N for x, y, z in XYZ:
        uf.union(x-1, y-1)
     x y z XYZ uf.union(x-1, y-1) uf.union uf union x-1 x 1 y-1 y 1 C = Counter(uf.parents()) C Counter(uf.parents()) Counter uf.parents() uf.parents uf parents return len(C) len(C) len C N N M M XYZ XYZ if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs)) __name__ == '__main__' __name__ '__main__' inputs = read() inputs read() read print(solve(*inputs)) print solve(*inputs) solve *inputs inputs class UnionFind():
    """Union-Find木の実装
    """

    def __init__(self, n):
        self.n = n
        self.parent = [x for x in range(n)]

    def find(self, x):
        """要素xが所属するグループを返す
        """
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def union(self, x, y):
        """要素x, yがそれぞれ所属するグループを併合する
        """
        x = self.find(x)
        y = self.find(y)
        if x > y:
            x, y = y, x
        self.parent[y] = x

    def parents(self):
        return [self.find(x) for x in range(self.n)] class UnionFind():
    """Union-Find木の実装
    """

    def __init__(self, n):
        self.n = n
        self.parent = [x for x in range(n)]

    def find(self, x):
        """要素xが所属するグループを返す
        """
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def union(self, x, y):
        """要素x, yがそれぞれ所属するグループを併合する
        """
        x = self.find(x)
        y = self.find(y)
        if x > y:
            x, y = y, x
        self.parent[y] = x

    def parents(self):
        return [self.find(x) for x in range(self.n)] UnionFind inputs = read() read() inputs input = sys.stdin.readline sys.stdin.readline input def read():
    N, M = map(int, input().strip().split())
    XYZ = []
    for i in range(M):
        x, y, z = map(int, input().strip().split())
        XYZ.append((x, y, z))
    return N, M, XYZ def read():
    N, M = map(int, input().strip().split())
    XYZ = []
    for i in range(M):
        x, y, z = map(int, input().strip().split())
        XYZ.append((x, y, z))
    return N, M, XYZ read def solve(N, M, XYZ):
    uf = UnionFind(N)
    for x, y, z in XYZ:
        uf.union(x-1, y-1)
    C = Counter(uf.parents())
    return len(C) def solve(N, M, XYZ):
    uf = UnionFind(N)
    for x, y, z in XYZ:
        uf.union(x-1, y-1)
    C = Counter(uf.parents())
    return len(C) solve
import sys
input = sys.stdin.readline
from collections import Counter


def read():
    N, M = map(int, input().strip().split())
    XYZ = []
    for i in range(M):
        x, y, z = map(int, input().strip().split())
        XYZ.append((x, y, z))
    return N, M, XYZ


class UnionFind():
    """Union-Find木の実装
    """

    def __init__(self, n):
        self.n = n
        self.parent = [x for x in range(n)]

    def find(self, x):
        """要素xが所属するグループを返す
        """
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def union(self, x, y):
        """要素x, yがそれぞれ所属するグループを併合する
        """
        x = self.find(x)
        y = self.find(y)
        if x > y:
            x, y = y, x
        self.parent[y] = x

    def parents(self):
        return [self.find(x) for x in range(self.n)]


def solve(N, M, XYZ):
    uf = UnionFind(N)
    for x, y, z in XYZ:
        uf.union(x-1, y-1)
    C = Counter(uf.parents())
    return len(C)


if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs))
