N,M = gets.split.map {|x| x.to_i}
arrs = []
M.times {
  x,y,z = gets.split.map {|x| x.to_i}
  xi = -1
  yi = -1
  arrs.each_with_index { |arr,i|
    if arr.include?(x)
      xi = i
    end
    if arr.include?(y)
      yi = i
    end
  }
  if (xi != -1) and (yi != -1)
    if xi != yi
      if xi < yi
        d = arrs.delete_at(yi)
        arrs[xi] += d
      else
        d = arrs.delete_at(xi)
        puts d
        arrs[yi] += d
      end
    end
  elsif (xi == -1) and (yi == -1)
    arrs << [x,y]
  elsif (xi != -1)
    arrs[xi].push(y)
  else
    arrs[yi].push(x)
  end
  
}

c = []
N.times { |i|
  c << i+1
}
arrs.each { |arr|
  c = c - arr
}
#p c.size
puts arrs.size + c.size

