#include <iostream> #include <string> #include <vector> #include <set> #include <algorithm> using namespace std; typedef struct node{ int node1; int node2; } node; bool comp1(node x,node y){ if(x.node1<y.node1) return true; else if(x.node1>y.node1) return false; else{ if(x.node2<y.node2) return true; else return false; } } bool comp2(node x,node y){ if(x.node1<y.node1) return false; else if(x.node1>y.node1) return true; else{ if(x.node2<y.node2) return false; else return true; } } int main(){ while(1){ int N,M; cin>>N; cin>>M; if(N==0&&M==0) break; set<int> people; vector<node> vct; for(int i=0;i<M;++i){ int p1,p2; cin>>p1>>p2; node nd; if(p1<p2){ nd.node1=p1; nd.node2=p2; } else{ nd.node1=p2; nd.node2=p1; } vct.push_back(nd); } people.insert(1); sort(vct.begin(),vct.end(),comp1); for(int i=0;i<M;++i){ if(people.find(vct[i].node1)!=people.end()) people.insert(vct[i].node2); } for(int i=M-1;i>=0;--i){ if(people.find(vct[i].node1)!=people.end()) people.insert(vct[i].node2); } for(int i=0;i<M;++i){ if(people.find(vct[i].node2)!=people.end()) people.insert(vct[i].node1); } for(int i=M-1;i>=0;--i){ if(people.find(vct[i].node2)!=people.end()) people.insert(vct[i].node1); } sort(vct.begin(),vct.end(),comp2); for(int i=0;i<M;++i){ if(people.find(vct[i].node1)!=people.end()) people.insert(vct[i].node2); } for(int i=M-1;i>=0;--i){ if(people.find(vct[i].node1)!=people.end()) people.insert(vct[i].node2); } for(int i=0;i<M;++i){ if(people.find(vct[i].node2)!=people.end()) people.insert(vct[i].node1); } for(int i=M-1;i>=0;--i){ if(people.find(vct[i].node2)!=people.end()) people.insert(vct[i].node1); } cout<<people.size()-1<<endl; } return 0; }