import sys input=sys.stdin.readline N,M,P=map(int,input().split()) A=set(map(int,input().split())) A=list(A) Max=max(A) T={} for b in A: a=b m=1 while b%P==0: b//=P m+=1 if b>1 and ((b not in T) or (T[b]>m)): T[b]=m if (not T) and Max<=M: print(-1) exit(0) def f(x,k): global X if k+1>=X: return float("inf") if x in Memo: return Memo[x] elif x>M: return 0 elif x*Max>M: return 1 X=float("inf") for b in T: m=T[b] X=min(X,f(x*b,k+m)+m) Memo[x]=X return X X=1 x=1 semi=max(T) while x*Max<=M: x*=semi X+=1 Memo={} print(f(1,0))