#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 5;
int par[maxn];
int d[maxn];
bool vis[maxn];
int n, m;
struct Edge {
  int from, to;
  Edge(int from, int to) : from(from), to(to) {}
};
vector<Edge> edges;
vector<int> G[maxn];
void init() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i <= n; i++) {
    G[i].erase(G[i].begin(), G[i].end());
    vis[i] = false;
    d[i] = 0;
  }
  edges.erase(edges.begin(), edges.end());
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    edges.push_back(Edge(u, v));
    edges.push_back(Edge(v, u));
    int l = edges.size();
    G[u].push_back(l - 2);
    G[v].push_back(l - 1);
  }
}
void solve() {
  int res = 0;
  for (int i = 1; i <= n; i++) {
    if (vis[i] == true) continue;
    bool flag = true;
    queue<int> que;
    que.push(i);
    vis[i] = true;
    d[i] = 1;
    while (!que.empty()) {
      int s = que.front();
      que.pop();
      d[s] = 2;
      int cnt = 0;
      for (int j = 0; j < G[s].size(); j++) {
        Edge x = edges[G[s][j]];
        if (d[x.to] >= 1) {
          cnt++;
          continue;
        }
        vis[x.to] = true;
        que.push(x.to);
        d[x.to] = 1;
      }
      if (cnt >= 2) flag = false;
    }
    res += flag;
  }
  printf("%d\n", res);
}
int main() {
  init();
  solve();
  return 0;
}
