#include<iostream>
using namespace std;
const int maxn=1000;
int father[maxn];
int degree[maxn];
int height[maxn];
void initial(int n){
for(int i=1;i<=n;i++){
father[i]=i;
degree[i]=0;
height[i]=0;
}
}
int find(int x){
if(x!=father[x]){
father[x]=find(father[x]);
}
return father[x];
}
void Union(int x,int y){
x=find(x);
y=find(y);
if(x!=y){
if(height[x]<height[y]){
father[x]=y;
}
else if(height[x]>height[y]){
father[y]=x;
}
else{
father[y]=x;
height[x]++;
}
}
}
int main(){
int n,m;
while(cin>>n){
if(n==0){
break;
}
cin>>m;
initial(n);
for(int i=0;i<m;i++){
int from,to;
cin>>from>>to;
if(from==to){
continue;
}
degree[from]++;
degree[to]++;
if(find(from)!=find(to)){
Union(from,to);
}
}
int flag=1;
for(int i=1;i<=n;i++){
if(degree[i]%2!=0){
flag=0;
}
}
for(int i=2;i<=n;i++){
if(find(i)!=find(1)&&find(i)!=i){
flag=0;
}
}
cout<<flag<<endl;
}
}