n = int(input()) v = set() z = {} for _ in range(n): x, y = map(int, input().split()) if x in v: z[x] += 1 else: v.add(x) z[x] = 1 if y in v: z[y] -= 1 else: v.add(y) z[y] = -1 count_p1 = 0 count_0 = 0 count_m1 = 0 for i in v: if z[i] == 0: count_0 += 1 elif z[i] == 1: count_p1 += 1 elif z[i] == -1: count_m1 += 1 if count_m1 == 1 and count_p1 == 1 and count_0 == len(v) - 2: print(1) elif count_0 == len(v): print(len(v)) else: print(0)