#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using namespace atcoder; #define rep(i,n) for (int i=0;i-1;i--) #define pb push_back #define all(x) (x).begin(), (x).end() template using vec = vector; template using vvec = vec>; template using vvvec = vec>; using ll = long long; using pii = pair; using pll = pair; template bool chmin(T &a, T b){ if (a>b){ a = b; return true; } return false; } template bool chmax(T &a, T b){ if (a T sum(vec x){ T res=0; for (auto e:x){ res += e; } return res; } template ostream& operator<<(ostream& os, const vec& A){ os << "["; rep(i,A.size()){ os << A[i]; if (i!=A.size()-1){ os << ' '; } } os<<"]"; return os; } template ostream& operator<<(ostream& os, const set& A){ os << "{"; for (auto e:A){ os << e; auto it = A.find(e); it++; if (it!=A.end()){ os << " "; } } os << "}"; return os; } template ostream& operator<<(ostream& os, const pair& A){ os << "(" << A.first <<", " << A.second << ")"; return os; } template ostream& operator<<(ostream& os, const deque& A){ os << "deque({"; rep(i,A.size()){ os << A[i]; if (i!=A.size()-1){ os << ' '; } } os<<"})"; return os; } using mint = modint998244353; ostream& operator<<(ostream& os, const mint& a){ os << a.val(); return os; } int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); ll N,M,A,B; cin>>N>>M>>A>>B; vec C(M); rep(i,M){cin>>C[i];} map D; vec d; for (ll i=1;i*i<=N;i++){ if ((N%i)==0){ D[i] = 1e18; D[N/i] = 1e18; d.pb(i); d.pb(N/i); } } sort(all(d)); D[1] = 0; for (auto a:d){ if (D[a]==1e18){continue;} //cout << D[a] << endl; ll next_max = 1e18/a; for (auto c:C){ if ((c%a)==0){ chmin(next_max,c/a-1); } } //cout << a << " " << next_max << endl; for (auto na:d){ if (a < na && (na%a)==0 && na <= next_max * a){ chmin(D[na],D[a]+(na/a-1)*A+B); } } } if (D[N]==1e18){ cout << -1 << endl; } else{ cout << D[N]-B << endl; } }