#include<iostream>
#include<iterator>
#include<set>
using namespace std;
int main()
{
	long n;
	cin >> n;
	set<long>ans;
	for(long d=1;d*d<=n;d++){
		if(n%d==0){
			ans.insert(d);
			ans.insert(n/d);
		}
	}

	for(auto x:ans)cout << x << endl;
}

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<bitset>
#include<cmath>
#include<ctime>
#include<queue>
#include<map>
#include<set>

#define int long long
#define lowbit(x) (x&(-x))
#define mid ((l+r)>>1)
#define lc (x<<1)
#define rc (x<<1|1)
#define max Max
#define min Min
#define abs Abs

using namespace std;

inline int read()
{
	int ans=0,f=1;
	char c=getchar();
	while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){ans=(ans<<1)+(ans<<3)+c-'0';c=getchar();}
	return ans*f;
}

inline void write(int x)
{
	if(x<0) putchar('-'),x=-x;
	if(x/10) write(x/10);
	putchar((char)(x%10)+'0');
}

template<typename T>inline T Abs(T a){return a>0?a:-a;};
template<typename T,typename TT>inline T Min(T a,TT b){return a>b?b:a;}
template<typename T,typename TT> inline T Max(T a,TT b){return a>b?a:b;}

int n,ans;

signed main()
{
	n=read();
	for(int i=1;i<=n;++i)
	{
		int p=i;
		int f1=1,f2=1;
		while(p)
		{
			if(p%10==7) f1=0;
			p/=10;
		}
		p=i;
		while(p)
		{
			if(p%8==7) f2=0;
			p/=8;
		}
		if(f1&&f2) ans++;
	}
	printf("%lld\n",ans);
	return 0;
}