--
local N, M = io.read("n", "n")

-- from ABC120
local parents = {}
for i=1,N do
    parents[i] = -1
end
local function find_root(x)
    while parents[x] > 0 do
        x = parents[x]
    end
    return x
end
local function find_union(a, b, update)
    local x, y = a, b
    while parents[x] > 0 do
        x = parents[x]
    end
    while parents[y] > 0 do
        y = parents[y]
    end
    local size_a, size_b = -parents[x], -parents[y]
    if update and x ~= y then
        if size_b > size_a then
            x, y = y, x
        end
        -- size(x) > size(y)
        -- x is new root of y
        parents[x] = parents[x] + parents[y]
        parents[y] = x
    end
    return x == y, size_a, size_b
end

for i=1,M do
    local a,b,z = io.read("n", "n", "n")
    find_union(a,b,true)
end

local set = {}
for i=1,N do
    local r = find_root(i)
    set[r] = true
end
local count = 0
for _ in pairs(set) do
    count = count + 1
end
print(count)