import heapq n, m, p = map(int, input().split()) a = list(map(int, input().split())) costs = [1] * n for i in range(len(a)): while a[i] % p == 0: a[i] //= p costs[i] += 1 if all([ai == 1 for ai in a]): print(-1) exit() def create_edges(a, costs): dic = {} INF = 1000000000 for i in range(len(a)): if dic.get(a[i], INF) > costs[i]: dic[a[i]] = costs[i] a = [] costs = [] for key in dic.keys(): a.append(key) costs.append(dic[key]) return a, costs def dijkstra(a, costs, m): distances = { 1 : 0 } queue = [(0, 1)] heapq.heapify(queue) INF = 1000000000 while len(queue) > 0: c, v = heapq.heappop(queue) if c > distances.get(v, INF): continue elif v > m: return c for i in range(len(a)): nxt = v * a[i] cst = c + costs[i] if cst < distances.get(nxt, INF): distances[nxt] = cst heapq.heappush(queue, (cst, nxt)) return INF a, costs = create_edges(a, costs) print(dijkstra(a, costs, m))