N, M, P = map(int, input().split()) A = list(map(int, input().split())) if M == 1: print(0) exit() ok = [] ng = [] for a in A: if a == 1: continue if a % P == 0: ng.append(a) else: ok.append(a) if ok: v = max(ok) ans = 0 x = 1 while x < M: x *= v ans += 1 print(ans) exit() if ng: ans = -1 for v in ng: tmp = v while tmp % P == 0: tmp //= P if tmp == 1: continue cnt = 0 x = 1 while x < M: if x % P == 0: x //= P else: x *= P cnt += 1 if ans == -1: ans = cnt else: cnt = min(cnt, ans) print(ans) exit() print(-1)