#include<bits/stdc++.h>
using namespace std;

const int oo = 1e9 + 7;
const int N = 1e5 + 7;

int n,m;
bool vis[N];
vector<int>v[N];

void bfs(int s){
    queue<int>q;
    q.push(s);

    vis[s] = 1;

    while(!q.empty()){
        int u = q.front();
        q.pop();

        for(auto x : v[u]){
            if(!vis[x]){
                vis[x] = 1;
                q.push(x);
            }
        }
    }
}

signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

    cin >> n >> m;

    for(int i=1; i <= m; i++){
        int a,b; cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }

    int cnt = 0;

    for(int i=1; i<=n; i++){
        if(!vis[i]){
            cnt++;
            bfs(i);
        }
    }

    cout << cnt;;
}
