import heapq import bisect from collections import defaultdict inf = 10 ** 18 N, M, P = map(int, input().split()) A = list(map(int, input().split())) last = max(A) if last > M: print(1) exit() dist = defaultdict(lambda: inf) edge = defaultdict(lambda: inf) found = False for a in A: cnt = 1 while a % P == 0: a //= P cnt += 1 if a == 1: continue edge[a] = min(edge[a], cnt) found = True if not found: print(-1) exit() que = [(0, 1)] dist[1] = 0 while que: ds, s = heapq.heappop(que) if dist[s] < ds: continue if s * last > M: print(ds + 1) break for t, dt in edge.items(): next = s * t if dist[next] > ds + dt: dist[next] = ds + dt heapq.heappush(que, (ds + dt, next))