#include <cstdio> #include <cstring> #include <iostream> using namespace std; const int N = 1e5 + 10; const int M = 2e5 + 10; bool f; struct Edge{ int to,nex; }e[M]; int head[N],idx,color[N]; void add_edge(int u,int v){ e[idx].to = v; e[idx].nex = head[u]; head[u] = idx++; } void dfs(int u,int fa){ for(int i = head[u];~i;i = e[i].nex){ int v = e[i].to; if(v == fa) continue; if(color[v]){ if(color[v] == color[u]) f = 1; continue; } color[v] = -color[u]; dfs(v,u); } } int cnt,n,m; int main(){ memset(head,-1,sizeof(head)); scanf("%d%d",&n,&m); while(m--){ int u,v;scanf("%d%d",&u,&v); add_edge(u,v),add_edge(v,u); } for(int i = 1;i <= n;i++){ if(!color[i]){ color[i] = 1; dfs(i,0); cnt++;//连通块数量 } } if(f) printf("%d\n",cnt - 1); else printf("%d\n",cnt); return 0; }