#include<bits/stdc++.h>
#define ll long long
using namespace std;
int read()
{
	char c;
	int w=1;
	while((c=getchar())>'9'||c<'0')if(c=='-')w=-1;
	int ans=c-'0';
	while((c=getchar())>='0'&&c<='9')ans=(ans<<1)+(ans<<3)+c-'0';
	return ans*w;
}
int n;
int a[20];
int b[20];
int tot1;
int tot2;
int main(){
	n=read();
	tot1=1;
	tot2=1;
	a[1]=1;
	b[1]=1;
	int res=0;
	for(int i=1;i<=n;i++)
	{
		int vis=1;
		for(int j=1;j<=tot1;j++)if(a[j]==7) vis=0;
		for(int j=1;j<=tot2;j++)if(b[j]==7) vis=0;
		res+=vis;
		a[1]++;
		int now=1;
		while(a[now]==10)
		{
			a[now]=0;
			a[now+1]++;
			now++;
		}
		b[1]++;
		tot1=max(tot1,now);
		now=1;
		while(b[now]==8)
		{
			b[now]=0;
			b[now+1]++;
			now++;
		}
		tot2=max(tot2,now);
	}
	cout<<res<<'\n';
	return 0;
}
#include<bits/stdc++.h>

using namespace std;

bool f(int x) {
    while(x) {
        int mod = x % 10;
        if(mod == 7) {
            return 1;
        }
        x /= 10;
    }
    return 0;
}

bool g(int x) {
    while(x) {
        int mod = x % 8;
        if(mod == 7) {
            return 1;
        }
        x /= 8;
    }
    return 0;
}

void solve() {
    //TODO:
    int n;
    cin >> n;
    int cnt = 0;
    for(int i = 1; i <= n; i++) {
        if(f(i) || g(i)) {
            cnt++;
        }
    }
    cout << n - cnt;
}

int main() {

    solve();
    return 0;
}