#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int N;
int M;
void DFS(int start, int ** arr, int * visited);
void BFS(int start, int ** arr, int * visited);
int main()
{
int idx;
int u;
int v;
int cnt;
int **arr;
int *visited;
scanf("%d %d", &N, &M);
arr = (int **)malloc(sizeof(int) * (N + 1));
idx = 0;
while (idx <= N)
{
arr[idx] = (int *)malloc(sizeof(int*) * (N + 1));
int idx2;
idx2 = 0;
while (idx2 <= N)
{
arr[idx][idx2] = 0;
idx2++;
}
idx++;
}
visited = (int *)malloc(sizeof(int) * (N + 1));
memset(visited, 0, sizeof(int) * (N + 1));
idx = 0;
while (idx < M)
{
scanf("%d %d", &u, &v);
arr[u][v] = 1;
arr[v][u] = 1;
idx++;
}
idx = 1;
cnt = 0;
while (idx <= N)
{
if (visited[idx] == 0)
{
BFS(idx, arr, visited);
cnt++;
}
idx++;
}
printf("%d", cnt);
}
void DFS(int start, int **arr, int *visited)
{
visited[start] = 1;
int idx;
idx = 1;
while (idx <= N)
{
if (arr[start][idx] == 1 && visited[idx] == 0)
{
DFS(idx, arr, visited);
}
idx++;
}
}
void BFS(int start, int **arr, int *visited)
{
visited[start] = 1;
int *queue;
queue = (int *)malloc(sizeof(int) * (N+1));
int front;
int rear;
int pop;
front = 0;
rear = 1;
queue[front] = start;
int idx;
while (front < rear)
{
idx = 1;
pop = queue[front];
while (idx <= N)
{
if (arr[pop][idx] == 1 && visited[idx] == 0)
{
visited[idx] = 1;
queue[rear] = idx;
rear++;
}
idx++;
}
front++;
}
}