#include<bits/stdc++.h>
using namespace std;
long long d[100001];
long long h;
int x[3];
long long a[50000001];
int tot=0;
void work(int x){
if(x/2>=1&&a[x]<a[x/2]){
swap(a[x],a[x/2]);
work(x/2);
}
}
void work1(int x){
if(a[x*2]<a[x*2+1]&&x*2+1<=tot&&a[x*2]<a[x]){
swap(a[x*2],a[x]);
work1(x*2);
}
else if(x*2+1<=tot&&a[x*2+1]<a[x]){
swap(a[x*2+1],a[x]);
work1(x*2+1);
}
else if(x*2+1>tot&&x*2<=tot&&a[x*2]<a[x]){
swap(a[x*2],a[x]);
work(x*2);
}
else{
return;
}
}
void bfs(long long p){
d[p%x[0]]=min(d[p%x[0]],p);
if(d[p%x[0]]!=p){
return;
}
if(p>=h||p<0){
return;
}
if(d[(p+x[1])%x[0]]==(1ll<<63)-1){
a[++tot]=p+x[1];
work(1);
}
if(d[(p+x[2])%x[0]]==(1ll<<63)-1){
a[++tot]=p+x[2];
work(1);
}
}
int main(){
scanf("%lld",&h);
h--;
scanf("%d%d%d",&x[0],&x[1],&x[2]);
sort(x,x+3);
for(int i=1;i<=x[0];i++){
d[i]=(1ll<<63)-1;
}
a[++tot]=0;
while(tot){
bfs(a[1]);
swap(a[1],a[tot]);
tot--;
work1(1);
}
long long ans=0;
for(int i=0;i<x[0];i++){
if(d[i]<=h){
ans+=(h-d[i])/x[0]+1;
}
}
printf("%lld",ans);
return 0;
}