import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(2*10**5+10) write = lambda x: sys.stdout.write(x+"\n") debug = lambda x: sys.stderr.write(x+"\n") writef = lambda x: print("{:.12f}".format(x)) n = int(input()) hw = [] m = 0 for _ in range(n): h,w = list(map(int, input().split())) hw.append((h,w)) m = max(m, h, w) ns = [[] for _ in range(n+m)] rns = [[] for _ in range(n+m)] u = 0 for h,w in hw: ns[u].append(n+w-1) ns[n+h-1].append(u) rns[n+w-1].append(u) rns[u].append(n+h-1) u += 1 v0 = v1 = 0 start = None for u in range(n+m): if len(ns[u])==len(rns[u]): pass elif len(ns[u])+1 == len(rns[u]): v0 += 1 elif len(rns[u])+1 == len(ns[u]): v1 += 1 start = u else: v0 = v1 = 100 break def euler_d(ns, start=0): """有向グラフのオイラー閉路 パスの場合はstartを奇数次数頂点にする """ n = len(ns) p = [] q = [start] r = [] vs = [0]*n while q: u = q.pop() u0 = u while vs[u]