import sys from collections import defaultdict input = sys.stdin.buffer.readline def solve(M, P, A): target = M // max(A) + 1 d = defaultdict(int) for a in A: c = 1 while a: if a % P: break a //= P c += 1 d[c] = max(d[c], a) d = dict(d) if target == 1: return 1 if max(A) != 1 else -1 if set(d.values()) == {1}: return -1 MAX = 10000 dp = [1] * (MAX + max(d) + 1) for i in range(MAX): if dp[i] >= target: return i + 1 for k, v in d.items(): dp[i + k] = max(dp[i + k], dp[i] * v) N, M, P = map(int, input().split()) A = tuple(map(int, input().split())) print(solve(M, P, A))