# import sys # input = sys.stdin.readline def mp():return map(int,input().split()) def lmp():return list(map(int,input().split())) import math import bisect from copy import deepcopy as dc from itertools import accumulate from collections import Counter, defaultdict, deque def ceil(U,V):return (U+V-1)//V def modf1(N,MOD):return (N-1)%MOD+1 n,m,p = mp() a = lmp() ag = [] for i in range(n): if math.gcd(a[i], p) == 1 and a[i] != 1: ag.append((a[i],1)) else: cnt = 0 while True: if a[i] % p == 0: cnt += 1 a[i] //= p else: break if a[i] != 1: ag.append((a[i],1+cnt)) if not ag: print(-1) exit() d = defaultdict(lambda:0) for i in range(len(ag)): d[ag[i][1]] = max(d[ag[i][1]], ag[i][0]) d = list(d.items()) stack = [(1,0)] ans = int(1e10) while stack: now = stack.pop() if now[0] >= m: ans = min(ans,now[1]) else: for i,j in d: stack.append((now[0]*j, now[i]+i)) print(ans)