#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,ans;
int read()
{
int x=0,f=1; char ch=getchar();
while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘) f=-1; ch=getchar();}
while(ch>=‘0‘&&ch<=‘9‘) {x=x*10+ch-‘0‘; ch=getchar();}
return x*f;
}
int work(int x)
{
while(x)
{
if(x%10==6) return 1;
x/=10;
}
return 0;
}
int main()
{
n=read();
for(int i=1;i<=n;i++)
if(i%6==0||work(i)) ans++;
printf("%d",ans);
return 0;
}