N = int(input()) C = 2 * (10 ** 5 ) + 1 hidari = [0] * C migi = [0] * C gyouretu = [] for _ in range(N): h,w = map(int,input().split()) gyouretu.append((h,w)) hidari[h] += 1 migi[w] += 1 import sys hidaricount = 0 migicount = 0 for i in range(1,C): if hidari[i] > migi[i]: hidaricount += hidari[i] - migi[i] ih = i elif hidari[i] < migi[i]: migicount += migi[i] - hidari[i] im = i if hidaricount > 1 or migicount > 1: print(0) exit() if hidaricount == 1: for h,w in gyouretu: if h == ih and w == im: print(0) exit() print(1) exit() ans = 0 for i in hidari: if i != 0: ans += 1 print(ans)