local ior = io.input()
local n, m = ior:read("*n", "*n")

local parent = {}
local groupsize = {}
for i = 1, n do parent[i] = i end
for i = 1, n do groupsize[i] = 1 end

local function getroot(idx)
  while(parent[idx] ~= idx) do
    idx = parent[idx]
  end
  return idx
end

for i = 1, m do
  local x, y, z = ior:read("*n", "*n", "*n")
  local xroot, yroot = getroot(x), getroot(y)
  if(groupsize[xroot] < groupsize[yroot]) then
    groupsize[yroot] = groupsize[xroot] + groupsize[yroot]
    parent[x] = yroot
    parent[xroot] = yroot
    parent[y] = yroot
  else
    groupsize[xroot] = groupsize[xroot] + groupsize[yroot]
    parent[x] = xroot
    parent[yroot] = xroot
    parent[y] = xroot
  end
end
local grouplist = {}
local cnt = 0
for i = 1, n do
  local r = getroot(i)
  if(grouplist[r] == nil) then
    grouplist[r] = true
    cnt = cnt + 1
  end
end
print(cnt)
