#include<iostream>
#include<queue>
using namespace std;
typedef unsigned long long ll;
const int N = 1e5 + 10;
int x, y, z; ll h, a[N], ans;
queue<ll> q;
int main(){
cin >> h >> x >> y >> z; h--;
q.push(y);
q.push(z);
while(q.size()){
ll tp = q.front();
q.pop();
if(tp > h) continue;
if(a[tp % x] % x == tp % x) continue;
a[tp % x] = tp;
q.push(tp+y);
q.push(tp+z);
}
for(int i = 0; i < x; i++){
if(a[i] % x == i) ans += (h-a[i])/x+1;
}
cout << ans;
return 0;
}