n,m=map(int,input().split())
class UnionFind:
    #def   -> foo=UnionFind(n,1)  <- 1-based index, default is 0
    #method -> foo.hoge(huga)
    __slots__ = ["_size", "_first_idx", "_parents"]
    def __init__(self, size: int, first_index: int = 0) -> None:
        self._size = size
        self._first_idx = first_index
        self._parents = [-1] * (size + first_index)
    def find(self, x: int) -> int:
        if self._parents[x] < 0:
            return x
        self._parents[x] = self.find(self._parents[x])
        return self._parents[x]
    def same(self, x: int, y: int) -> bool:
        return self.find(x) == self.find(y)
    def unite(self, x: int, y: int) -> bool:
        x, y = self.find(x), self.find(y)
        if x == y:
            return False
        if self._parents[x] > self._parents[y]:
            x, y = y, x
        self._parents[x] += self._parents[y]
        self._parents[y] = x
        return True
    def size(self, x: int) -> int:
        return -self._parents[self.find(x)]
    def group_count(self) ->int:
        return sum([1 for i in  self._parents if i<0])-self._first_idx
    def connected(self) ->bool:
        return self._parents[self.find(self._first_idx)]==-self._size

uf=UnionFind(n,1)
for i in range(m):
    x,y,z=map(int,input().split())
    uf.unite(x,y)
print(uf.group_count()) n,m=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m class UnionFind:
    #def   -> foo=UnionFind(n,1)  <- 1-based index, default is 0
    #method -> foo.hoge(huga)
    __slots__ = ["_size", "_first_idx", "_parents"]
    def __init__(self, size: int, first_index: int = 0) -> None:
        self._size = size
        self._first_idx = first_index
        self._parents = [-1] * (size + first_index)
    def find(self, x: int) -> int:
        if self._parents[x] < 0:
            return x
        self._parents[x] = self.find(self._parents[x])
        return self._parents[x]
    def same(self, x: int, y: int) -> bool:
        return self.find(x) == self.find(y)
    def unite(self, x: int, y: int) -> bool:
        x, y = self.find(x), self.find(y)
        if x == y:
            return False
        if self._parents[x] > self._parents[y]:
            x, y = y, x
        self._parents[x] += self._parents[y]
        self._parents[y] = x
        return True
    def size(self, x: int) -> int:
        return -self._parents[self.find(x)]
    def group_count(self) ->int:
        return sum([1 for i in  self._parents if i<0])-self._first_idx
    def connected(self) ->bool:
        return self._parents[self.find(self._first_idx)]==-self._size UnionFind __slots__ = ["_size", "_first_idx", "_parents"] __slots__ ["_size", "_first_idx", "_parents"] "_size" "_first_idx" "_parents" def __init__(self, size: int, first_index: int = 0) -> None:
        self._size = size
        self._first_idx = first_index
        self._parents = [-1] * (size + first_index)
     __init__ self._size = size self._size self _size size self._first_idx = first_index self._first_idx self _first_idx first_index self._parents = [-1] * (size + first_index) self._parents self _parents [-1] * (size + first_index) [-1] -1 size + first_index size first_index self self size: int size first_index: int = 0 first_index 0 def find(self, x: int) -> int:
        if self._parents[x] < 0:
            return x
        self._parents[x] = self.find(self._parents[x])
        return self._parents[x]
     find if self._parents[x] < 0:
            return 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: int x def same(self, x: int, y: int) -> bool:
        return self.find(x) == self.find(y)
     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: int x y: int y def unite(self, x: int, y: int) -> bool:
        x, y = self.find(x), self.find(y)
        if x == y:
            return False
        if self._parents[x] > self._parents[y]:
            x, y = y, x
        self._parents[x] += self._parents[y]
        self._parents[y] = x
        return True
     unite x, y = self.find(x), self.find(y) x self.find(x) self.find self find x y self.find(y) self.find self find y if x == y:
            return False
         x == y x y return False False if self._parents[x] > self._parents[y]:
            x, y = y, x
         self._parents[x] > self._parents[y] self._parents[x] self._parents self _parents x self._parents[y] self._parents self _parents y x, y = y, x x y y x 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 return True True self self x: int x y: int y def size(self, x: int) -> int:
        return -self._parents[self.find(x)]
     size return -self._parents[self.find(x)] -self._parents[self.find(x)] self._parents[self.find(x)] self._parents self _parents self.find(x) self.find self find x self self x: int x def group_count(self) ->int:
        return sum([1 for i in  self._parents if i<0])-self._first_idx
     group_count 1 for i in  self._parents if i<0 for i in  self._parents if i<0 i self._parents self _parents i<0 i 0 if i<0 1 return sum([1 for i in  self._parents if i<0])-self._first_idx sum([1 for i in  self._parents if i<0])-self._first_idx sum([1 for i in  self._parents if i<0]) sum [1 for i in  self._parents if i<0] self._first_idx self _first_idx self self def connected(self) ->bool:
        return self._parents[self.find(self._first_idx)]==-self._size connected return self._parents[self.find(self._first_idx)]==-self._size self._parents[self.find(self._first_idx)]==-self._size self._parents[self.find(self._first_idx)] self._parents self _parents self.find(self._first_idx) self.find self find self._first_idx self _first_idx -self._size self._size self _size self self uf=UnionFind(n,1) uf UnionFind(n,1) UnionFind n 1 for i in range(m):
    x,y,z=map(int,input().split())
    uf.unite(x,y) 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.unite(x,y) uf.unite uf unite x y print(uf.group_count()) print uf.group_count() uf.group_count uf group_count uf=UnionFind(n,1) UnionFind(n,1) uf x,y,z=map(int,input().split()) map(int,input().split()) x n,m=map(int,input().split()) map(int,input().split()) n z=map(int,input().split()) map(int,input().split()) z m=map(int,input().split()) map(int,input().split()) m class UnionFind:
    #def   -> foo=UnionFind(n,1)  <- 1-based index, default is 0
    #method -> foo.hoge(huga)
    __slots__ = ["_size", "_first_idx", "_parents"]
    def __init__(self, size: int, first_index: int = 0) -> None:
        self._size = size
        self._first_idx = first_index
        self._parents = [-1] * (size + first_index)
    def find(self, x: int) -> int:
        if self._parents[x] < 0:
            return x
        self._parents[x] = self.find(self._parents[x])
        return self._parents[x]
    def same(self, x: int, y: int) -> bool:
        return self.find(x) == self.find(y)
    def unite(self, x: int, y: int) -> bool:
        x, y = self.find(x), self.find(y)
        if x == y:
            return False
        if self._parents[x] > self._parents[y]:
            x, y = y, x
        self._parents[x] += self._parents[y]
        self._parents[y] = x
        return True
    def size(self, x: int) -> int:
        return -self._parents[self.find(x)]
    def group_count(self) ->int:
        return sum([1 for i in  self._parents if i<0])-self._first_idx
    def connected(self) ->bool:
        return self._parents[self.find(self._first_idx)]==-self._size class UnionFind:
    #def   -> foo=UnionFind(n,1)  <- 1-based index, default is 0
    #method -> foo.hoge(huga)
    __slots__ = ["_size", "_first_idx", "_parents"]
    def __init__(self, size: int, first_index: int = 0) -> None:
        self._size = size
        self._first_idx = first_index
        self._parents = [-1] * (size + first_index)
    def find(self, x: int) -> int:
        if self._parents[x] < 0:
            return x
        self._parents[x] = self.find(self._parents[x])
        return self._parents[x]
    def same(self, x: int, y: int) -> bool:
        return self.find(x) == self.find(y)
    def unite(self, x: int, y: int) -> bool:
        x, y = self.find(x), self.find(y)
        if x == y:
            return False
        if self._parents[x] > self._parents[y]:
            x, y = y, x
        self._parents[x] += self._parents[y]
        self._parents[y] = x
        return True
    def size(self, x: int) -> int:
        return -self._parents[self.find(x)]
    def group_count(self) ->int:
        return sum([1 for i in  self._parents if i<0])-self._first_idx
    def connected(self) ->bool:
        return self._parents[self.find(self._first_idx)]==-self._size UnionFind y,z=map(int,input().split()) map(int,input().split()) y
n,m=map(int,input().split())
class UnionFind:
    #def   -> foo=UnionFind(n,1)  <- 1-based index, default is 0
    #method -> foo.hoge(huga)
    __slots__ = ["_size", "_first_idx", "_parents"]
    def __init__(self, size: int, first_index: int = 0) -> None:
        self._size = size
        self._first_idx = first_index
        self._parents = [-1] * (size + first_index)
    def find(self, x: int) -> int:
        if self._parents[x] < 0:
            return x
        self._parents[x] = self.find(self._parents[x])
        return self._parents[x]
    def same(self, x: int, y: int) -> bool:
        return self.find(x) == self.find(y)
    def unite(self, x: int, y: int) -> bool:
        x, y = self.find(x), self.find(y)
        if x == y:
            return False
        if self._parents[x] > self._parents[y]:
            x, y = y, x
        self._parents[x] += self._parents[y]
        self._parents[y] = x
        return True
    def size(self, x: int) -> int:
        return -self._parents[self.find(x)]
    def group_count(self) ->int:
        return sum([1 for i in  self._parents if i<0])-self._first_idx
    def connected(self) ->bool:
        return self._parents[self.find(self._first_idx)]==-self._size

uf=UnionFind(n,1)
for i in range(m):
    x,y,z=map(int,input().split())
    uf.unite(x,y)
print(uf.group_count())