from sys import stdin n, *indata = map(int, stdin.read().split()) offset = 0 gnum = [0 for i in range((10**5)*2+1)] ginv = [0 for i in range((10**5)*2+1)] g = [[] for i in range((10**5)*2+1)] appeared = set() for i in range(n): s, t = indata[offset + 2*i],indata[offset + 2*i+1] g[s].append(t) g[t].append(s) gnum[s] += 1 ginv[t] += 1 appeared.add(s) appeared.add(t) check = [False for i in range((10**5)*2+1)] kari = appeared.pop() que = [kari] check[kari] = True while que: now = que.pop() for i in g[now]: if not check[i]: que.append(i) check[i] = True for i in appeared: if not check[i]: print("{}".format(0)) exit() plusused = False minusused = False for i in range(1,(10**5)*2+1): if abs(gnum[i] - ginv[i]) >= 2: print("{}".format(0)) exit() elif gnum[i] - ginv[i] == 1: if plusused: print("{}".format(0)) exit() else: plusused = True elif gnum[i] - ginv[i] == 1: if minusused: print("{}".format(0)) exit() else: minusused = True if plusused: print("{}".format(1)) exit() ans = 0 for i in range(1,(10**5)*2+1): if gnum[i]: ans += 1 print("{}".format(ans))