N, M = map(int, input().split())
par = [i for i in range(N+1)]
h = [1 for _ in range(N+1)]

def root(x):
    if par[x] == x:
        return x
    par[x] = root(par[x])
    return par[x]

def unite(x,y):
    rx = root(x)
    ry = root(y)
    if h[rx] < h[ry]:
        rx, ry = ry, rx
    h[rx] += h[ry]
    par[ry] = rx

for _ in range(M):
    x,y,z = map(int, input().split())
    unite(x,y)

for i in range(1,N+1):
    par[i] = root(i)

print(len(set(par[1:]))) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M i for i in range(N+1) for i in range(N+1) i range(N+1) range N+1 N 1 for i in range(N+1) i par = [i for i in range(N+1)] par [i for i in range(N+1)] 1 for _ in range(N+1) for _ in range(N+1) _ range(N+1) range N+1 N 1 for _ in range(N+1) 1 h = [1 for _ in range(N+1)] h [1 for _ in range(N+1)] def root(x):
    if par[x] == x:
        return x
    par[x] = root(par[x])
    return par[x] root if par[x] == x:
        return x
     par[x] == x par[x] par x x return x x par[x] = root(par[x]) par[x] par x root(par[x]) root par[x] par x return par[x] par[x] par x x x def unite(x,y):
    rx = root(x)
    ry = root(y)
    if h[rx] < h[ry]:
        rx, ry = ry, rx
    h[rx] += h[ry]
    par[ry] = rx unite rx = root(x) rx root(x) root x ry = root(y) ry root(y) root y if h[rx] < h[ry]:
        rx, ry = ry, rx
     h[rx] < h[ry] h[rx] h rx h[ry] h ry rx, ry = ry, rx rx ry ry rx h[rx] += h[ry] h[rx] h rx h[ry] h ry par[ry] = rx par[ry] par ry rx x x y y for _ in range(M):
    x,y,z = map(int, input().split())
    unite(x,y) _ 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 unite(x,y) unite x y for i in range(1,N+1):
    par[i] = root(i) i range(1,N+1) range 1 N+1 N 1 par[i] = root(i) par[i] par i root(i) root i print(len(set(par[1:]))) print len(set(par[1:])) len set(par[1:]) set par[1:] par 1: 1 def unite(x,y):
    rx = root(x)
    ry = root(y)
    if h[rx] < h[ry]:
        rx, ry = ry, rx
    h[rx] += h[ry]
    par[ry] = rx def unite(x,y):
    rx = root(x)
    ry = root(y)
    if h[rx] < h[ry]:
        rx, ry = ry, rx
    h[rx] += h[ry]
    par[ry] = rx unite N, M = map(int, input().split()) map(int, input().split()) N h = [1 for _ in range(N+1)] [1 for _ in range(N+1)] h y,z = map(int, input().split()) map(int, input().split()) y M = map(int, input().split()) map(int, input().split()) M x,y,z = map(int, input().split()) map(int, input().split()) x par = [i for i in range(N+1)] [i for i in range(N+1)] par def root(x):
    if par[x] == x:
        return x
    par[x] = root(par[x])
    return par[x] def root(x):
    if par[x] == x:
        return x
    par[x] = root(par[x])
    return par[x] root z = map(int, input().split()) map(int, input().split()) z
N, M = map(int, input().split())
par = [i for i in range(N+1)]
h = [1 for _ in range(N+1)]

def root(x):
    if par[x] == x:
        return x
    par[x] = root(par[x])
    return par[x]

def unite(x,y):
    rx = root(x)
    ry = root(y)
    if h[rx] < h[ry]:
        rx, ry = ry, rx
    h[rx] += h[ry]
    par[ry] = rx

for _ in range(M):
    x,y,z = map(int, input().split())
    unite(x,y)

for i in range(1,N+1):
    par[i] = root(i)

print(len(set(par[1:])))
