//    created: 16.02.2021 03:26:23

#include <iostream>
#include <numeric>
#include <cmath>
#include<vector>
using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define REPD(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<=int(b);i++)
#define FORD(i,a,b) for(int i=a;i>=int(b);i--)

int decimalNumber(int n){
    int tmp = 0;
    while (n)
    {
        tmp = n % 10;
        n = n / 10;
        if(tmp == 7){
            return false;
        }
    }
    return true;
}

int eightBase(int n){
    int tmp = 0;
    while (n)
    {
        tmp = n % 8;
        n = n / 8;
        if(tmp == 7){
            return false;
        }
    }
    return true;
}

int main() {
    cin.tie(0);
     ios_base::sync_with_stdio(false);
    int N;
    int ans=0;
    cin >> N;
    FOR(i,1,N){
        if (decimalNumber(i)){
            if (eightBase(i))ans++;
        }
    }
    cout << ans << endl;
    return 0;
}
#include <bits/stdc++.h>
using Int = long long;  // clang-format off
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define RREP_(i, a_, b_, a, b, ...) for (Int i = Int(b) - 1, low##i = (a); i >= low##i; i--)
#define RREP(i, ...) RREP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define ALL(v) std::begin(v), std::end(v)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on
struct in {
    template <class T> operator T() {
        T t;
        std::cin >> t;
        return t;
    }
};
void out() { std::cout << "\n"; }
template <class Head, class... Tail> void out(Head&& h, Tail&&... t) {
    std::cout << h << (sizeof...(Tail) == 0 ? "" : " "), out(std::forward<Tail>(t)...);
}
template <class T> bool chmin(T& a, const T& b) { return a > b ? a = b, true : false; }
template <class T> bool chmax(T& a, const T& b) { return a < b ? a = b, true : false; }
template <class T> using V = std::vector<T>;

/**
 *    author:  knshnb
 *    created: Sat Dec 19 21:02:02 JST 2020
 **/

signed main() {
    Int n = in();
    Int ans = 0;
    REP(x, 1, n + 1) {
        bool ok = true;
        for (Int d : {10, 8}) {
            Int y = x;
            while (y) {
                if (y % d == 7) ok = false;
                y /= d;
            }
        }
        ans += ok;
    }
    out(ans);
}
