class UnionFind
  def initialize(n)
    @parents = Array.new(n) { |i| i }
  end

  def find(x)
    return x if @parents[x] == x
    @parents[x] = find(@parents[x])
  end

  def same?(x, y)
    find(x) == find(y)
  end

  def unite(x, y)
    x_root = find(x)
    y_root = find(y)

    return if x_root == y_root

    @parents[y_root] = x_root
  end

  def size
    n = 0
    @parents.each_with_index { |x, i| n += 1 if x == i }
    n
  end
end

def one_or_two(n, params)
  u = UnionFind.new(n)
  params.each do |x, y, z|
    u.unite(x - 1, y - 1)
  end
  u.size
end

n, m = gets.split.map(&:to_i)
params = []
m.times do
  params << gets.split.map(&:to_i)
end

puts one_or_two(n, params)