#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long N,i,count  = 0,count1  = 0,temp,temp1;
    cin>>N;
    bool v[N+1] = {false};
    for(i = 1; i <= N; i++)
    {
        temp = i;
        while(temp != 0)
        {
            if(temp % 10 == 7)
            {
                if(v[i-1] == false)
                {
                    count++;
                    v[i-1] = true;

                }
                break;
            }
            temp = temp /10;
        }
    }
    for(i = 1; i <= N; i++)
    {
        temp1 = i;
        while(temp1 != 0)
        {
            if(temp1 % 8 == 7)
            {
                if(v[i-1] == false)
                {
                    count1++;
                    v[i-1] = true;

                }
                break;
            }
            temp1 = temp1 / 8;
        }
    }
    cout<<N-(count+count1)<<endl;
}




#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    cin>>n;
    int a=0;
    for(int i=1;i<=n;i++){
        int x=i;
		int y=i;
        bool z=1;
        while(x>0){
            if(x%10==7) z=0;
            x/=10;
        }
        while(y>0){
            if(y%8==7) z=0;
            y/=8;
        }
        if(z) a++;
    }
    cout<<a<<endl;
}
