#include <iostream>
#include <vector>
#include <stdexcept>
#include <string>
#include <strstream>
#include <sstream>
int main(){
    int N;
    scanf("%d\n",&N);
    int num=0;
    for (int i=1; i<=N; i++) {
        std::string S;
        std::string V;
        S = std::to_string(i);
        std::stringstream ss;
        ss << std::oct << i;
        V = ss.str();
        for (int j=0; j<V.size(); j++) {
            if (S[j]=='7' || V[j]=='7') {
                num++;
                break;
            }
        }
    }
    printf("%d\n",N-num);
}

//#include <atcoder/maxflow.hpp>
#include <memory>
#include <iostream>
#include <map>
#include <list>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>
#include <complex>
#include <thread>

#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s

typedef long long ll;

using namespace std;
//using namespace atcoder;

ll modd = (1000LL * 1000LL * 1000LL + 7LL);
//ll modd = 998244353;

int main()   {

    ios_base::sync_with_stdio(false);

    cout.precision(17);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no

    auto start = chrono::steady_clock::now();

//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readint(n);
        int ct = 0;
        forr(i,1,n) {
            bool has7 = false;
            int nn = i;
            while (nn>0) {
                if (nn%10==7) {has7=true;}
                nn/=10;
            }
            nn = i;
            while (nn>0) {
                if (nn%8==7) {has7=true;}
                nn/=8;
            }
            if (!has7) {
                ++ct;
            }
        }
        cout << ct << endl;
    }
//        auto stop = chrono::steady_clock::now(); 
//        auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start);
//        cout << "Duration: " << duration.count() << endl;
    return 0;
}

