#include <iostream>
#include <fstream>
#include <vector>
//#define FIN "dfs.in"
//#define FOUT "dfs.out"
typedef unsigned long ulong;
class ConnectedComponents {
public:
//constructor of the class
ConnectedComponents(std::vector<std::vector<ulong>* >& adjacencyList, ulong nVertices, ulong nEdges)
: adjList(adjacencyList),
numVertices(nVertices),
numEdges(nEdges),
count(0)
{
isVisited.resize(numVertices + 1, false);
}
void execute() {
for(ulong node = 1; node <= numVertices; ++node) {
if(!isVisited[ node ]) {
dfs(node);
count++;
}
}
}
void dfs(ulong node) {
if( !isVisited[node] ) {
isVisited[ node ] = true;
if( adjList[node] ) {
for(ulong i = 0; i < adjList[node]->size(); ++i ) {
dfs((*adjList[node])[i] );
}
}
}
}
ulong getCount() const {
return count;
}
private:
ulong numVertices;
ulong numEdges;
std::vector<std::vector<ulong>* >& adjList;
ulong count;
std::vector<bool> isVisited;
};
int main(int argc, char const *argv[])
{
ulong n,
m,
x,
y;
std::cin>>n>>m;
std::vector<std::vector<ulong>* > adjList;
adjList.resize(n + 1, NULL);
for(ulong i = 1; i <= m; ++i) {
std::cin>>x>>y;
if(adjList[x] == NULL) {
adjList[x] = new std::vector<ulong>();
}
if(adjList[y] == NULL) {
adjList[y] = new std::vector<ulong>();
}
adjList[x]->push_back(y);
adjList[y]->push_back(x);
}
ConnectedComponents connex(adjList, n, m);
connex.execute();
std::cout<<connex.getCount();
std::cout<<"\n";
//clean up
for(ulong i = 0; i < adjList.size(); ++i) {
if(adjList[i] != NULL) delete adjList[i];
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8ZnN0cmVhbT4KI2luY2x1ZGUgPHZlY3Rvcj4KLy8jZGVmaW5lIEZJTiAiZGZzLmluIgovLyNkZWZpbmUgRk9VVCAiZGZzLm91dCIKCnR5cGVkZWYgdW5zaWduZWQgbG9uZyB1bG9uZzsKCmNsYXNzIENvbm5lY3RlZENvbXBvbmVudHMgewoKICAgICAgcHVibGljOgoKICAgICAgCSAgICAgLy9jb25zdHJ1Y3RvciBvZiB0aGUgY2xhc3MKICAgICAgCSAgICAgQ29ubmVjdGVkQ29tcG9uZW50cyhzdGQ6OnZlY3RvcjxzdGQ6OnZlY3Rvcjx1bG9uZz4qID4mIGFkamFjZW5jeUxpc3QsIHVsb25nIG5WZXJ0aWNlcywgdWxvbmcgbkVkZ2VzKSAKICAgICAgCSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICA6IGFkakxpc3QoYWRqYWNlbmN5TGlzdCksIAogICAgICAJICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbnVtVmVydGljZXMoblZlcnRpY2VzKSwgCiAgICAgIAkgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBudW1FZGdlcyhuRWRnZXMpLAogICAgICAJICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY291bnQoMCkgCiAgICAgIAkgICAgICAgICAgewoKICAgICAgCSAgICAgICAgICAgICAgIGlzVmlzaXRlZC5yZXNpemUobnVtVmVydGljZXMgKyAxLCBmYWxzZSk7ICAKCiAgICAgIAkgICAgICAgICAgfQoKICAgICAgCSAgICAgdm9pZCBleGVjdXRlKCkgewoKICAgICAgICAgICAgICAgICAgZm9yKHVsb25nIG5vZGUgPSAxOyBub2RlIDw9IG51bVZlcnRpY2VzOyArK25vZGUpIHsKCiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYoIWlzVmlzaXRlZFsgbm9kZSBdKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBkZnMobm9kZSk7CgogICAgICAgICAgICAgICAgICAgICAgICAgIAkgICAgIGNvdW50Kys7CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgICAgfSAKICAgICAgCSAgICAgfSAKCgogICAgICAJICAgICB2b2lkIGRmcyh1bG9uZyBub2RlKSB7CiAKICAgICAgICAgICAgICAgICAgaWYoICFpc1Zpc2l0ZWRbbm9kZV0gKSB7CgogICAgICAgICAgICAgICAgICAgICAgIGlzVmlzaXRlZFsgbm9kZSBdID0gdHJ1ZTsKCiAgICAgICAgICAgICAgICAgICAgICAgaWYoIGFkakxpc3Rbbm9kZV0gKSB7CgogICAgICAgICAgICAgICAgICAgICAgIAkgICBmb3IodWxvbmcgaSA9IDA7IGkgPCBhZGpMaXN0W25vZGVdLT5zaXplKCk7ICsraSApIHsKCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBkZnMoKCphZGpMaXN0W25vZGVdKVtpXSApOwogICAgICAgICAgICAgICAgICAgICAgICAgICB9ICAgICAgICAgICAgICAgICAgICAgICAgICAJICAgCiAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9IAoKICAgICAgCSAgICAgfQoKICAgICAgCSAgICAgdWxvbmcgZ2V0Q291bnQoKSBjb25zdCB7CgogICAgICAgICAgICAgICAgICAgcmV0dXJuIGNvdW50OyAKICAgICAgCSAgICAgfSAgICAgICAgICAgIAoKICAgICAgcHJpdmF0ZTogCiAgICAgIAkgICAgIHVsb25nIG51bVZlcnRpY2VzOwogICAgICAJICAgICB1bG9uZyBudW1FZGdlczsKICAgICAgCSAgICAgc3RkOjp2ZWN0b3I8c3RkOjp2ZWN0b3I8dWxvbmc+KiA+JiBhZGpMaXN0OwogICAgICAJICAgICB1bG9uZyBjb3VudDsKICAgICAgCSAgICAgc3RkOjp2ZWN0b3I8Ym9vbD4gaXNWaXNpdGVkOyAgCn07CgppbnQgbWFpbihpbnQgYXJnYywgY2hhciBjb25zdCAqYXJndltdKQp7CgogICAgdWxvbmcgbiwgCiAgICAgICAgICBtLCAKICAgICAgICAgIHgsIAogICAgICAgICAgeTsKCiAgICAgICAgICBzdGQ6OmNpbj4+bj4+bTsKCiAgICAgICAgICBzdGQ6OnZlY3RvcjxzdGQ6OnZlY3Rvcjx1bG9uZz4qID4gYWRqTGlzdDsKCiAgICAgICAgICBhZGpMaXN0LnJlc2l6ZShuICsgMSwgTlVMTCk7CgogICAgICAgICAgZm9yKHVsb25nIGkgPSAxOyBpIDw9IG07ICsraSkgewoKICAgICAgICAgIAkgIHN0ZDo6Y2luPj54Pj55OwoKICAgICAgICAgICAgICBpZihhZGpMaXN0W3hdID09IE5VTEwpIHsKICAgICAgICAgICAgICAJIGFkakxpc3RbeF0gPSBuZXcgc3RkOjp2ZWN0b3I8dWxvbmc+KCk7CiAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICBpZihhZGpMaXN0W3ldID09IE5VTEwpIHsKICAgICAgICAgICAgICAJIGFkakxpc3RbeV0gPSBuZXcgc3RkOjp2ZWN0b3I8dWxvbmc+KCk7CiAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICBhZGpMaXN0W3hdLT5wdXNoX2JhY2soeSk7CiAgICAgICAgICAgICAgYWRqTGlzdFt5XS0+cHVzaF9iYWNrKHgpOwogICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIAkKIAogICAgQ29ubmVjdGVkQ29tcG9uZW50cyBjb25uZXgoYWRqTGlzdCwgbiwgbSk7ICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICBjb25uZXguZXhlY3V0ZSgpOwogICAgICAgICAgICAgICAgICAgICAgICBzdGQ6OmNvdXQ8PGNvbm5leC5nZXRDb3VudCgpOwogICAgICAgICAgICAgICAgICAgICAgICBzdGQ6OmNvdXQ8PCJcbiI7CgoKICAgIC8vY2xlYW4gdXAKCiAgICBmb3IodWxvbmcgaSA9IDA7IGkgPCBhZGpMaXN0LnNpemUoKTsgKytpKSB7CgogICAgCWlmKGFkakxpc3RbaV0gIT0gTlVMTCkgZGVsZXRlIGFkakxpc3RbaV07IAogICAgfSAgICAgICAgICAgICAgICAgICAgICAgIAoKCglyZXR1cm4gMDsKfQ==