#include <bits/stdc++.h>
using namespace std;
// clang-format off
using ll = int64_t;
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
    for (auto& a : v) cin >> a;
    return is;
}
template <class T>
istream& operator>>(istream& is, vector<pair<T, T>>& v) {
    for (auto& a : v) cin >> a.first >> a.second;
    return is;
}
template <class T>
istream& operator>>(istream& is, vector<tuple<T, T, T>>& v) {
    for (auto& a : v) {
        T a1, a2, a3;
        cin >> a1 >> a2 >> a3;
        a = {a1, a2, a3};
    }
    return is;
}
template <class T>
ostream& operator<<(ostream& os, vector<T>& v) {
    for (auto& a : v) os << a << " ";
    os << endl;
    return os;
}
template <class T>
inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true; }
    return false;
}
template <class T>
inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true; }
    return false;
}
#define all(v) begin(v), end(v)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using veci = vector<int>;
using vecll = vector<ll>;
using Pi = pair<int, int>;
using Pll = pair<ll, ll>;
using Ti = tuple<int, int, int>;
// clang-format on
// cout << std::fixed << std::setprecision(15);

bool isd7(int d) {
    while (d > 0) {
        if (d % 10 == 7) return false;
        d /= 10;
    }
    return true;
}

int isd8(int d) {
    while (d > 0) {
        if (d % 8 == 7) return false;
        d /= 8;
    }
    return true;
}

int main() {
    int N;
    cin >> N;
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        if (isd7(i) && isd8(i)) ans++;
    }
    cout << ans << endl;
}
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

bool f(int n){
  string s = to_string(n);
  for(auto c : s){
    if(c == '7') return false;
  }
  while(n != 0){
    int now = n % 8;
    if(now == 7) return false;
    n /= 8;
  }
  return true;
}

int main(){
  int n;
  cin >> n;
  n++;
  int ans = 0;
  rep2(i, 1, n){
    if(f(i) == true) ans++;
  }
  cout << ans << endl;
  return 0;
}