import heapq INF = 1 << 60 n, m, p = map(int, input().split()) a = list(map(int, input().split())) if any([x > m for x in a]): print("1") exit() idx = {} q = [] for i in range(n): cur = a[i] cnt = 1 while cur % p == 0: cnt += 1 cur //= p q.append((a[i], cur)) if idx.get(cnt, None) is None or a[idx[cnt]] < a[i]: idx[cnt] = i dist = {} dist[1] = 0 hp = [(0, 1)] ans = INF while len(hp) > 0: cd, cur = heapq.heappop(hp) if cd > dist[cur]: continue for cost, i in idx.items(): ai, d = q[i] nxt = cur * ai if dist.get(nxt, INF) > dist[cur] + 1: if nxt > m: ans = min(ans, dist[cur] + 1) nxt = cur * d if dist.get(nxt, INF) > dist[cur] + cost: if nxt > m: ans = min(ans, dist[cur] + cost) else: dist[nxt] = dist[cur] + cost heapq.heappush(hp, (dist[nxt], nxt)) if ans < INF: print(ans) else: print("-1")