#include<bits/stdc++.h>
using namespace std;
using OO=pair<long long,int>;
const int oi=1e5+1;
priority_queue<OO,vector<OO>,greater<OO>> h;
long long sz[3],sz2[oi],n,ans;
int main(){
cin>>n>>sz[0]>>sz[1]>>sz[2],n--;
fill(sz2,sz2+sz[0],-1);
for(h.push({0,0});!h.empty();){
OO p=h.top();
h.pop();
if(sz2[p.second]==-1){
sz2[p.second]=p.first;
h.push({p.first+sz[1],(p.second+sz[1])%sz[0]});
h.push({p.first+sz[2],(p.second+sz[2])%sz[0]});
}
}
for(int i=0;i<sz[0];i++){
(sz2[i]!=-1 && n>= sz2[i]) && (ans+=(n-sz2[i])/sz[0]+1);
}
cout<<ans;
return 0;
}