local n, m = io.read("*n", "*n")
local parent = {}
for i = 1, n do
  parent[i] = i
end

local function uf_findroot(idx)
  local idx_update = idx
  while parent[idx] ~= idx do
    idx = parent[idx]
  end
  while parent[idx_update] ~= idx do
    parent[idx_update], idx_update = idx, parent[idx_update]
  end
  return idx
end

for i = 1, m do
  local x, y, _z = io.read("*n", "*n", "*n")
  local xp, yp = uf_findroot(x), uf_findroot(y)
  parent[yp], parent[y] = xp, xp
end

local c = 0
local map = {}
for i = 1, n do
  local p = uf_findroot(i)
  if not map[p] then
    c = c + 1
    map[p] = true
  end
end
print(c)
