import sys



input = sys.stdin.readline

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

pair = {}

rank = {}

def root(x):

    if x == pair[x]:

        return x

    else:

        pair[x] = root(pair[x])

    return pair[x]



def unite(x, y):

    rx = root(x)

    ry = root(y)

    if rx > ry:

        pair[rx] = pair[ry]

    else:

        pair[ry] = pair[rx]



for i in range(1, N+1):

    pair.setdefault(i, i)



for i in range(1, N+1):

    rank.setdefault(i, 0)



tmp = []

for i in range(M):

    tmp.append(list(map(int, input().split())))

tmp.sort()

for i in range(M):

    x, y = tmp[i][0], tmp[i][1]

    if x < y:

        unite(x, y)

    else:

        unite(y, x)



cnt = set()

for k, y in list(pair.items()):

    y = root(y)

    cnt.add(y)

print((len(cnt)))

import sys



input = sys.stdin.readline

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

pair = {}

rank = {}

def root(x):

    if x == pair[x]:

        return x

    else:

        pair[x] = root(pair[x])

    return pair[x]



def unite(x, y):

    rx = root(x)

    ry = root(y)

    if rx > ry:

        pair[rx] = pair[ry]

    else:

        pair[ry] = pair[rx]



for i in range(1, N+1):

    pair.setdefault(i, i)



for i in range(1, N+1):

    rank.setdefault(i, 0)



for i in range(M):

    x, y, z = list(map(int, input().split()))

    if x < y:

        unite(x, y)

    else:

        unite(y, x)



cnt = set()

for k, y in list(pair.items()):

    y = root(y)

    cnt.add(y)

print((len(cnt)))

import sys

input = sys.stdin.readline
N, M = list(map(int, input().split()))
pair = {}
rank = {}


def root(x):
    if x == pair[x]:
        return x
    else:
        pair[x] = root(pair[x])
    return pair[x]


def unite(x, y):
    rx = root(x)
    ry = root(y)
    if rx > ry:
        pair[rx] = pair[ry]
    else:
        pair[ry] = pair[rx]


for i in range(1, N + 1):
    pair.setdefault(i, i)
for i in range(1, N + 1):
    rank.setdefault(i, 0)
tmp = []
for i in range(M):
    tmp.append(list(map(int, input().split())))
tmp.sort()
for i in range(M):
    x, y = tmp[i][0], tmp[i][1]
    if x < y:
        unite(x, y)
    else:
        unite(y, x)
cnt = set()
for k, y in list(pair.items()):
    y = root(y)
    cnt.add(y)
print((len(cnt)))

import sys

input = sys.stdin.readline
N, M = list(map(int, input().split()))
pair = {}
rank = {}


def root(x):
    if x == pair[x]:
        return x
    else:
        pair[x] = root(pair[x])
    return pair[x]


def unite(x, y):
    rx = root(x)
    ry = root(y)
    if rx > ry:
        pair[rx] = pair[ry]
    else:
        pair[ry] = pair[rx]


for i in range(1, N + 1):
    pair.setdefault(i, i)
for i in range(1, N + 1):
    rank.setdefault(i, 0)
for i in range(M):
    x, y, z = list(map(int, input().split()))
    if x < y:
        unite(x, y)
    else:
        unite(y, x)
cnt = set()
for k, y in list(pair.items()):
    y = root(y)
    cnt.add(y)
print((len(cnt)))

-tmp = [] -    tmp.append(list(map(int, input().split()))) -tmp.sort() -for i in range(M): -    x, y = tmp[i][0], tmp[i][1] +    x, y, z = list(map(int, input().split()))