#================================================ from functools import lru_cache import sys,heapq input=sys.stdin.readline N,M,P=map(int,input().split()) A=list(set(map(int,input().split()))) D={} for a in A: b=a m=1 while a%P==0: a//=P m+=1 D[b]=(m,a) if not D: print(-1) exit(0) T={1:0} Q=[(0,1)] heapq.heapify(Q) while Q: d,x=heapq.heappop(Q) if x>M or d>T[x]: continue for b in D: m,a=D[b] if x*b>M and ((x*b not in T) or (T[x*b]>d+1)): T[x*b]=d+1 Q.append((d+1,x*b)) if a>1 and (x*a not in T) or T[x*a]>d+m: T[x*a]=d+m Q.append((d+m,x*a)) X=float("inf") for x in T: if x>M: X=min(X,T[x]) print(X if X