import java.util.ArrayList;
import java.util.Scanner;
public class Main {
static ArrayList<Integer>[] graph;
static int[] visited;
static int N, M;
public static void DFS(int c) {
if(visited[c] == 1) {
return;
}
visited[c] = 1;
for (int i : graph[c]) {
if (visited[i] == 0) {
DFS(i);
}
}
}
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
N = kb.nextInt();
M = kb.nextInt();
graph = new ArrayList[N+1];
visited = new int[N+1];
for (int i = 1; i <= N; i++) {
graph[i] = new ArrayList<>();
}
for(int i=0; i<M ; i++) {
int s = kb.nextInt();
int e = kb.nextInt();
// 무방향 그래프
graph[s].add(e);
graph[e].add(s);
}
int answer = 0;
for(int i=1; i<N+1; i++) {
if(visited[i] == 0) {
DFS(i);
answer++;
}
}
System.out.println(answer);
}
}