N=int(input()) A=list(map(int,input().split())) B=[list(map(int,input().split())) for i in range(N)] P=A[0] X=[1] for i in range(1<