# なぜか、「終点と終点の前の頂点」の組としてありうる個数を数えようとしていたのはおかしい。 # 行列の積なんだから始点と終点です。はい。 # その後の考察もおかしかった。オイラー路に対する理解もおかしかった。 import sys input = sys.stdin.readline N=int(input()) HW=[tuple(map(int,input().split())) for i in range(N)] DEG=[0]*(2*10**5+1) # UnionFind Group = [i for i in range(2*10**5+1)] # グループ分け Nodes = [1]*(2*10**5+1) # 各グループのノードの数 def find(x): while Group[x] != x: x=Group[x] return x def Union(x,y): if find(x) != find(y): if Nodes[find(x)] < Nodes[find(y)]: Nodes[find(y)] += Nodes[find(x)] Nodes[find(x)] = 0 Group[find(x)] = find(y) else: Nodes[find(x)] += Nodes[find(y)] Nodes[find(y)] = 0 Group[find(y)] = find(x) for h,w in HW: Union(h,w) DEG[h]+=1 DEG[w]-=1 X=find(HW[0][0]) for h,w in HW: if find(h)!=X or find(w)!=X: print(0) exit() one=0 minus=0 other=0 for i in range(2*10**5+1): if DEG[i]==1: one+=1 elif DEG[i]==-1: minus+=1 elif DEG[i]!=0: other+=1 if other!=0: print(0) elif one==0 and minus==0: print(len(set([h for h,w in HW])|set([w for h,w in HW]))) elif one==1 and minus==1: print(1) else: print(0)