import sys
sys.setrecursionlimit(10**9)
n,m = map(int, input().split())

rel = [[] for _ in range(n)]
for i in range(m):
  x,y,z = map(int, input().split())
  rel[x-1].append(y-1)
  rel[y-1].append(x-1)

ans = [-1]*n
def hoge(parent, pos):
  for i in rel[pos]:
    if ans[i] >= 0:
      continue
    ans[i] = pos
    hoge(pos, i)
  return

cnt = 0
for i in range(n):
  if ans[i] < 0:
    hoge(0, i)
    cnt += 1

print(cnt) import sys sys sys.setrecursionlimit(10**9) sys.setrecursionlimit sys setrecursionlimit 10**9 10 9 n,m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m [] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [] rel = [[] for _ in range(n)] rel [[] for _ in range(n)] for i in range(m):
  x,y,z = map(int, input().split())
  rel[x-1].append(y-1)
  rel[y-1].append(x-1) i range(m) range m x,y,z = map(int, input().split()) x map(int, input().split()) map int input().split() ().split () input split y z rel[x-1].append(y-1) [x-1].append [x-1] rel x-1 x 1 append y-1 y 1 rel[y-1].append(x-1) [y-1].append [y-1] rel y-1 y 1 append x-1 x 1 ans = [-1]*n ans [-1]*n [-1] -1 n def hoge(parent, pos):
  for i in rel[pos]:
    if ans[i] >= 0:
      continue
    ans[i] = pos
    hoge(pos, i)
  return hoge for i in rel[pos]:
    if ans[i] >= 0:
      continue
    ans[i] = pos
    hoge(pos, i)
   i rel[pos] rel pos if ans[i] >= 0:
      continue
     ans[i] >= 0 ans[i] ans i 0 continue ans[i] = pos ans[i] ans i pos hoge(pos, i) hoge pos i return parent parent pos pos cnt = 0 cnt 0 for i in range(n):
  if ans[i] < 0:
    hoge(0, i)
    cnt += 1 i range(n) range n if ans[i] < 0:
    hoge(0, i)
    cnt += 1 ans[i] < 0 ans[i] ans i 0 hoge(0, i) hoge 0 i cnt += 1 cnt 1 print(cnt) print cnt z = map(int, input().split()) map(int, input().split()) z x,y,z = map(int, input().split()) map(int, input().split()) x y,z = map(int, input().split()) map(int, input().split()) y cnt += 1 1 cnt rel = [[] for _ in range(n)] [[] for _ in range(n)] rel n,m = map(int, input().split()) map(int, input().split()) n cnt = 0 0 cnt ans = [-1]*n [-1]*n ans m = map(int, input().split()) map(int, input().split()) m def hoge(parent, pos):
  for i in rel[pos]:
    if ans[i] >= 0:
      continue
    ans[i] = pos
    hoge(pos, i)
  return def hoge(parent, pos):
  for i in rel[pos]:
    if ans[i] >= 0:
      continue
    ans[i] = pos
    hoge(pos, i)
  return hoge
import sys
sys.setrecursionlimit(10**9)
n,m = map(int, input().split())

rel = [[] for _ in range(n)]
for i in range(m):
  x,y,z = map(int, input().split())
  rel[x-1].append(y-1)
  rel[y-1].append(x-1)

ans = [-1]*n
def hoge(parent, pos):
  for i in rel[pos]:
    if ans[i] >= 0:
      continue
    ans[i] = pos
    hoge(pos, i)
  return

cnt = 0
for i in range(n):
  if ans[i] < 0:
    hoge(0, i)
    cnt += 1

print(cnt)