#include <bits/stdc++.h>
using namespace std;
vector<long long int> adj[100005];
long long int visited[100005];
long long int counter;
long long int answer;
long long int maxcounter = INT_MIN;
long long int n, m;
double countedges;
double countnodes;
void dfs(int i) {
  visited[i] = 1;
  countedges += adj[i].size() / 2.0;
  countnodes++;
  for (int j = 0; j < adj[i].size(); j++) {
    if (!visited[adj[i][j]]) dfs(adj[i][j]);
  }
}
int main() {
  cin >> n >> m;
  int a, b;
  for (int i = 0; i < m; i++) {
    scanf("%d", &a);
    scanf("%d", &b);
    adj[a - 1].push_back(b - 1);
    adj[b - 1].push_back(a - 1);
  }
  for (int i = 0; i < n; i++) {
    countedges = 0;
    countnodes = 0;
    if (!visited[i]) {
      dfs(i);
    }
    if (countnodes == (countedges + 1)) {
      answer++;
    }
  }
  cout << answer << endl;
}
