N, M, P = map(int, input().split()) A = list(map(int, input().split())) maxa = max(A) from collections import defaultdict dp = defaultdict(lambda: float('inf')) check = defaultdict(lambda: False) cnts = [1]*N for i in range(N): while A[i]%P==0: cnts[i] += 1 A[i] //= P from heapq import * lis = [] x = 1 dp[1] = 0 if max(A)==1 and maxa<=M: print(-1) exit() while x * maxa <= M: for i in range(N): dp[x*A[i]] = min(dp[x*A[i]], dp[x]+cnts[i]) if not check[x*A[i]]: heappush(lis, x*A[i]) check[x*A[i]] = True x = heappop(lis) if x>M: print(dp[x]) else: print(dp[x]+1)