#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<vector>usingnamespace std;int n, m;//城镇数目和道路数目int pre[1005];voidinit(){for(int i =1; i <= n; i++){
pre[i]= i;//开始将每个结点的根结点设为自己}}intfind(int x){if(pre[x]!= x){returnfind(pre[x]);}return x;}voidjoin(int x,int y){int xx =find(x);int yy =find(y);if(xx != yy){
pre[x]= yy;// 改了这里,但是一直不对,不知道为啥
pre[xx]= yy;}}intmain(){while(scanf("%d",&n)&& n !=0){scanf("%d",&m);// cout<<"Right cin"<<endl;当N为0 时,输入结束init();int l, r;for(int i =1; i <= m; i++){scanf("%d %d",&l,&r);if(find(l)!=find(r)){//两个暂时还未联通join(l, r);}}int sum[1005];int nn =0;memset(sum,0,sizeof(sum));for(int i =1; i <= n; i++){
sum[pre[i]]=1;}for(int i =1; i <= n; i++){if(sum[i]==1) nn++;}
cout << nn -1<< endl;}}