N=int(input()) P=[list(map(int,input().split())) for i in range(N)] from itertools import permutations L=list(permutations(range(N))) ANS=0 for X in L: now=0 for x in X: l,r=P[x] if r