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

//Standard input
bool checkMod7(int n, int mod){
    for(; n > 0; n = n / mod){
        if(n % mod == 7) return true;
    }
    return false;
}

int main(){
    int N, counter;
    bool dec_flag, oct_flag;
    cin >> N;
    counter = N;
    for(int i = N; i > 0; i--){
        if(checkMod7(i, 10) || checkMod7(i, 8)) counter--;
    }
    cout << counter << endl;
    return 0; //Must return 0 if you want to use return statement
}
        #include<bits/stdc++.h>
        using namespace std;

        #define ff              first
        #define ss              second
        #define int             long long
        #define pb              push_back
        #define mp              make_pair
        #define pii             pair<int,int>
        #define vi              vector<int>
        #define mii             map<int,int>
        #define pqb             priority_queue<int>
        #define pqs             priority_queue<int,vi,greater<int> >
        #define setbits(x)      __builtin_popcountll(x)
        #define zrobits(x)      __builtin_ctzll(x)
        #define ps(x,y)         fixed<<setprecision(y)<<x
        #define mk(arr,n,type)  type *arr=new type[n];
        #define w(x)            int x; cin>>x; while(x--)
        #define fo(i, n)        for (int i = 0; i < n; i++)
        #define Fo(i, k, n)     for (int i = k; i < n; i++)
        #define all(v)          v.begin(), v.end()
        #define allr(v)          v.rbegin(), v.rend()
        #define endl            '\n'
        //mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

        bool decimal(int n){
        bool flag=0;
        int l = 0;

        while(n){
            l = n%10;
            n = n/10;
            if(l==7){
                flag=1; break;
            }
        }

        if(flag) return 1;
        return 0;
        }

        bool octal(int n){
        int flag=0;
        //cout << pow << endl;

        while(n){
          if(n%8 == 7){
            flag = 1; break;
          }
          n = n/8;
        }

        if(flag) return 1;
        else return 0;
        }

        int32_t main()
        {

        int c, x=INT_MAX , t, i, y, sum=0, n, m;
        t = 1;
       ///cin >> t;
        while(t--){
             cin >> n ;
         Fo(i, 1, n+1){
         if(!decimal(i) && !octal(i))
                sum++;
         }

         cout << sum;


        }
        }


