N,M,P = map(int,input().split()) A = list(map(int,input().split())) INF = 10 ** 9 ans = INF for i in range(N): a = A[i] while a % P == 0: a //= P if a > 1: cnt = 0 now = 1 while M >= now: now *= a cnt += 1 ans = min(ans,cnt) if ans == INF: print(-1) else: print(ans)