import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); int p = sc.nextInt(); int max = 0; TreeMap map = new TreeMap<>(); for (int i = 0; i < n; i++) { int x = sc.nextInt(); max = Math.max(max, x); int count = 0; while (x % p == 0) { x /= p; count++; } map.put(count, Math.max(map.getOrDefault(count, 0), x)); } boolean all1 = true; for (int x : map.values()) { if (x > 1) { all1 = false; break; } } int limit = m / max; if (limit < 1) { System.out.println(1); return; } if (all1) { System.out.println(-1); return; } int ans = Integer.MAX_VALUE; Integer current = 0; TreeMap dp = new TreeMap<>(); dp.put(1, 0); while ((current = dp.higherKey(current)) != null) { for (Map.Entry entry : map.entrySet()) { int count = entry.getKey() + 1; int value = entry.getValue(); if (value == 1) { continue; } if (current * (long)value > limit) { ans = Math.min(ans, dp.get(current) + count); } else { if (!dp.containsKey(current * value) || dp.get(current * value) > dp.get(current) + count) { dp.put(current * value, dp.get(current) + count); } } } } System.out.println(ans + 1); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }