N,M=map(int,input().split())

flag=list(range(N))
def takeflag(p):
    stock=[]
    while flag[flag[p]]!=flag[p]:
        stock.append(p)
        p=flag[p]
    p=flag[p]
    for i in stock:
        flag[i]=p
    return p

for i in range(M):
    x,y,z = map(int,input().split())
    x,y=x-1,y-1
    x,y = map(takeflag,(x,y))
    x,y = min(x,y),max(x,y)
    flag[x]=y

st=set()
for i in range(N):
    st.add(takeflag(i))

print(len(st)) N,M=map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M flag=list(range(N)) flag list(range(N)) list range(N) range N def takeflag(p):
    stock=[]
    while flag[flag[p]]!=flag[p]:
        stock.append(p)
        p=flag[p]
    p=flag[p]
    for i in stock:
        flag[i]=p
    return p takeflag stock=[] stock [] while flag[flag[p]]!=flag[p]:
        stock.append(p)
        p=flag[p]
     flag[flag[p]]!=flag[p] flag[flag[p]] flag flag[p] flag p flag[p] flag p stock.append(p) stock.append stock append p p=flag[p] p flag[p] flag p p=flag[p] p flag[p] flag p for i in stock:
        flag[i]=p
     i stock flag[i]=p flag[i] flag i p return p p p p for i in range(M):
    x,y,z = map(int,input().split())
    x,y=x-1,y-1
    x,y = map(takeflag,(x,y))
    x,y = min(x,y),max(x,y)
    flag[x]=y 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,y=x-1,y-1 x x-1 x 1 y y-1 y 1 x,y = map(takeflag,(x,y)) x map(takeflag,(x,y)) map takeflag (x,y) x y y x,y = min(x,y),max(x,y) x min(x,y) min x y y max(x,y) max x y flag[x]=y flag[x] flag x y st=set() st set() set for i in range(N):
    st.add(takeflag(i)) i range(N) range N st.add(takeflag(i)) st.add st add takeflag(i) takeflag i print(len(st)) print len(st) len st z = map(int,input().split()) map(int,input().split()) z x,y = map(takeflag,(x,y)) map(takeflag,(x,y)) x x,y,z = map(int,input().split()) map(int,input().split()) x flag=list(range(N)) list(range(N)) flag y,z = map(int,input().split()) map(int,input().split()) y x,y=x-1,y-1 x-1 x N,M=map(int,input().split()) map(int,input().split()) N y = map(takeflag,(x,y)) map(takeflag,(x,y)) y y = min(x,y),max(x,y) max(x,y) y M=map(int,input().split()) map(int,input().split()) M x,y = min(x,y),max(x,y) min(x,y) x st=set() set() st y=x-1,y-1 y-1 y def takeflag(p):
    stock=[]
    while flag[flag[p]]!=flag[p]:
        stock.append(p)
        p=flag[p]
    p=flag[p]
    for i in stock:
        flag[i]=p
    return p def takeflag(p):
    stock=[]
    while flag[flag[p]]!=flag[p]:
        stock.append(p)
        p=flag[p]
    p=flag[p]
    for i in stock:
        flag[i]=p
    return p takeflag
N,M=map(int,input().split())

flag=list(range(N))
def takeflag(p):
    stock=[]
    while flag[flag[p]]!=flag[p]:
        stock.append(p)
        p=flag[p]
    p=flag[p]
    for i in stock:
        flag[i]=p
    return p

for i in range(M):
    x,y,z = map(int,input().split())
    x,y=x-1,y-1
    x,y = map(takeflag,(x,y))
    x,y = min(x,y),max(x,y)
    flag[x]=y

st=set()
for i in range(N):
    st.add(takeflag(i))

print(len(st))