import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")



n,m = map(int, input().split())
from collections import defaultdict
ns = defaultdict(set)
for i in range(m):
    x,y,z = map(int, input().split())
    x -= 1
    y -= 1
    ns[x].add(y)
    ns[y].add(x)
    
seen = [False]*n
ans = 0
for start in range(n):
    if seen[start]:
        continue
    q = [(start, -1)]
    seen[start] = True
    val = None
    while q:
        u, prev = q.pop()
        for v in ns[u]:
            if v==prev:
                continue
            if seen[v]:
                val = 1
            else:
                seen[v] = True
                q.append((v, u))
    if val is None:
        val = 1
    ans += val
print(ans) import sys sys input = lambda : sys.stdin.readline().rstrip() input lambda : sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip sys.setrecursionlimit(max(1000, 10**9)) sys.setrecursionlimit sys setrecursionlimit max(1000, 10**9) max 1000 10**9 10 9 write = lambda x: sys.stdout.write(x+"\n") write lambda x: sys.stdout.write(x+"\n") sys.stdout.write(x+"\n") sys.stdout.write sys.stdout sys stdout write x+"\n" x "\n" x n,m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m from collections import defaultdict ns = defaultdict(set) ns defaultdict(set) defaultdict set for i in range(m):
    x,y,z = map(int, input().split())
    x -= 1
    y -= 1
    ns[x].add(y)
    ns[y].add(x)
     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 x -= 1 x 1 y -= 1 y 1 ns[x].add(y) [x].add [x] ns x add y ns[y].add(x) [y].add [y] ns y add x seen = [False]*n seen [False]*n [False] False n ans = 0 ans 0 for start in range(n):
    if seen[start]:
        continue
    q = [(start, -1)]
    seen[start] = True
    val = None
    while q:
        u, prev = q.pop()
        for v in ns[u]:
            if v==prev:
                continue
            if seen[v]:
                val = 1
            else:
                seen[v] = True
                q.append((v, u))
    if val is None:
        val = 1
    ans += val start range(n) range n if seen[start]:
        continue
     seen[start] seen start continue q = [(start, -1)] q [(start, -1)] (start, -1) start -1 seen[start] = True seen[start] seen start True val = None val None while q:
        u, prev = q.pop()
        for v in ns[u]:
            if v==prev:
                continue
            if seen[v]:
                val = 1
            else:
                seen[v] = True
                q.append((v, u))
     q u, prev = q.pop() u q.pop() q.pop q pop prev for v in ns[u]:
            if v==prev:
                continue
            if seen[v]:
                val = 1
            else:
                seen[v] = True
                q.append((v, u))
     v ns[u] ns u if v==prev:
                continue
             v==prev v prev continue if seen[v]:
                val = 1
            else:
                seen[v] = True
                q.append((v, u))
     seen[v] seen v val = 1 val 1 seen[v] = True seen[v] seen v True q.append((v, u)) q.append q append (v, u) v u if val is None:
        val = 1
     val is None val None val = 1 val 1 ans += val ans val print(ans) print ans input = lambda : sys.stdin.readline().rstrip() lambda : sys.stdin.readline().rstrip() input y -= 1 1 y q = [(start, -1)] [(start, -1)] q write = lambda x: sys.stdout.write(x+"\n") lambda x: sys.stdout.write(x+"\n") write val = 1 1 val m = map(int, input().split()) map(int, input().split()) m x -= 1 1 x u, prev = q.pop() q.pop() u n,m = map(int, input().split()) map(int, input().split()) n x,y,z = map(int, input().split()) map(int, input().split()) x prev = q.pop() q.pop() prev ns = defaultdict(set) defaultdict(set) ns z = map(int, input().split()) map(int, input().split()) z seen = [False]*n [False]*n seen ans = 0 0 ans val = None None val ans += val val ans y,z = map(int, input().split()) map(int, input().split()) y val = 1 1 val
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")



n,m = map(int, input().split())
from collections import defaultdict
ns = defaultdict(set)
for i in range(m):
    x,y,z = map(int, input().split())
    x -= 1
    y -= 1
    ns[x].add(y)
    ns[y].add(x)
    
seen = [False]*n
ans = 0
for start in range(n):
    if seen[start]:
        continue
    q = [(start, -1)]
    seen[start] = True
    val = None
    while q:
        u, prev = q.pop()
        for v in ns[u]:
            if v==prev:
                continue
            if seen[v]:
                val = 1
            else:
                seen[v] = True
                q.append((v, u))
    if val is None:
        val = 1
    ans += val
print(ans)