import sys sys.setrecursionlimit(10 ** 7) n = int(input()) cnt = [0 for i in range(2 * 10 ** 5)] G = [[] for i in range(n)] s = set() for _ in range(n): h, w = map(int, input().split()) G[h - 1].append(w - 1) G[w - 1].append(h - 1) cnt[h - 1] += 1 cnt[w - 1] -= 1 s.add(h - 1) s.add(w - 1) vis = [0] * (2 * 10 ** 5) def dfs(v): vis[v] = 1 for u in G[v]: if not vis[u]: dfs(u) dfs(0) if not all(vis[i] for i in s): exit(print(0)) tmp = sum(abs(cnt[i]) for i in range(2 * 10 ** 5)) if tmp == 0: print(n) else: print(1)