#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
const int H=3000000;
long long n,i,j,k,ps=-1;
struct Ha
{
long long num,sum;
Ha* next;
Ha()
{
num=-1;
}
}Hash[H],T[H+100000];
void add(Ha *p,long long num,long long sum)
{
if (p->num==-1)
{
p->num=num;
p->sum=sum;
return;
}
Ha *x=p;
while (x->next) x=x->next;
++ps;
x->next=T+ps;
x=x->next;
x->num=num;
x->sum=sum;
}
long long find(long long num)
{
Ha *x=Hash+num%H;
for (;;)
{
if (!x) return -1;
if (x->num==num) return x->sum;
x=x->next;
}
return -1;
}
void dp(long long n)
{
long long re=0;
if (find(n/2)==-1) dp(n/2);
if (find(n/3)==-1) dp(n/3);
if (find(n/5)==-1) dp(n/5);
if (find(n/7)==-1) dp(n/7);
re+=find(n/2)+find(n/3)+find(n/5)+find(n/7);
add(Hash+n%H,n,re);
}
int main()
{
freopen("losttemple.in","r",stdin);
freopen("losttemple.out","w",stdout);
cin>>n;
Hash[0].num=0;
Hash[0].sum=Hash[1].sum=1;
Hash[1].num=1;
dp(n);
cout<<find(n)<<endl;
return 0;
}