N,M,P = map(int, input().split()) A = list(map(int, input().split())) divA = [0]*N cntDiv = [0]*N maxA = max(A) if maxA>M: print(1) exit() aaa=0 for i in range(N): cnt = 0 temp = A[i] while temp % P ==0: temp=temp//P cnt+=1 divA[i]=temp cntDiv[i]=cnt aaa=max(aaa,temp/(cnt+1)) if divA.count(1)==N: print(-1) exit() cnt = 1 x = 1 while maxA*x