#include<bits/stdc++.h>
#define rt register int
using namespace std;int ans,x,y,num,f[100010];
int main()
{
while(x!=-1&&y!=-1)
{
scanf("%d%d",&x,&y);if(x==-1&&y==-1)return 0;
while(x&&y){f[x]=f[y]=1;scanf("%d%d",&x,&y);++num;}
for(rt i=1;i<=100010;++i) if(f[i]) ++ans;
if(ans-1==num) printf("1\n");
else printf("0\n");
memset(f,0,sizeof(f));ans=num=0;
}return 0;
}
/*
6 8 5 3 5 2 6 4
5 6 0 0
8 1 7 3 6 2 8 9 7 5
7 4 7 8 7 6 0 0
3 8 6 8 6 4
5 3 5 6 5 2 0 0
-1 -1
*/