count_node, count_edge = map(int, input().split())
node_matrix = [[] for i in range(count_node + 1)]
visited = [False for _ in range(count_node + 1)]
for i in range(count_edge):
    x, y = map(int, input().split())
    node_matrix[x].append(y)
    node_matrix[y].append(x)

count = 0
for i in range(len(node_matrix) - 1):
    start_node = i + 1
    if visited[start_node]:
        continue
    q = [start_node]
    visited[start_node] = True
    while q:
        next_node = q.pop(0)
        for el in node_matrix[next_node]:
            if not visited[el]:
                visited[el] = True
                q.append(el)
    count += 1
print(count)
