#define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(v) v.begin(), v.end() typedef long long ll; #include using namespace std; ll p; ll f(ll x){ while(x%p==0) x/=p; return x; } int main(){ ll n,m; cin>>n>>m>>p; vector A(n); rep(i,n) cin>>A[i]; ll ma=0; rep(i,n) ma=max(ma,A[i]); ll g=(m+ma-1)/ma; vector B(n); rep(i,n) B[i]=f(A[i]); ll ma1=0; rep(i,n) ma1=max(ma1,B[i]); if(ma1<2){ cout<<-1<