#include <algorithm>
#include <array>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <vector>

using namespace std;

using ll = long long;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define sz(x) (int)(x).size()
#define ms(arr, v) memset(arr, v, sizeof(arr))
#define f first
#define s second
#define pb push_back

// clang-format off
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T_vector>void output_vector(const T_vector &v, bool add_one = false, int start = -1, int end = -1) {if (start < 0) start = 0; if (end < 0) end = int(v.size()); for (int i = start; i < end; i++) cout << v[i] + (add_one ? 1 : 0) << (i < end - 1 ? ' ' : '\n');}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << "(" << v.first << ":" << v.second << ")" << ","; os << "}"; return os; }


auto random_address = [] {char *p = new char; delete p;return uint64_t(p);};
const uint64_t SEED = chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1);
mt19937_64 rng(SEED);
// clang-format on

void solve() { }

int main() {
     int n;
     cin >> n;
     int ans = 0;
     set<int> st;
     for (int i = 1; i <= n; ++i) {
          bool ok = true;
          for (int base : { 8, 10 }) {
               int x = i;
               while (x > 0) {
                    if (x % base == 7) ok = false;
                    x /= base;
               }
          }
          if (ok)
               ++ans;
     }
     // for (auto x : st)
     //      cout << x << " ";
     // cout << st.size();
     cout << ans << endl;
     return 0;
}
#include<iostream>
using namespace std;
int main(){
  int a,i,ii,N,co=0,b;
  cin >> N;
  for(i=1;i<=N;i++){
    a=0;
    if(i%10==7||i%100-i%10==70||i%1000-i%100==700||i%10000-i%1000==7000||i%100000-i%10000==70000){
      a=a+1;
    }
    for(ii=i;ii>0;i=i){
      b=ii%8;
      ii=ii/8;
      if(b==7)a=a+1;
    }
    if(a==0)co=co+1;
  }
  cout << co << endl;
  return 0;
}