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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
using Graph = vector<vector<int>>;

bool isOK(int n);

int main(){
    int N; cin>>N;
    int res = 0;
    rep1(i,N)res += isOK(i)?1:0;
    cout<<res<<endl;
}

bool isOK(int n){
    //10進数で7check;
    int n1 = n, n2 = n;
    while(n1){
        if(n1%10==7)return false;
        n1/=10;
    }
    while(n2){
        if(n2%8==7)return false;
        n2/=8;
    }
    return true;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define ROF(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define REP(i, n) FOR(i, 0, (n)-1)
#define sqr(x) ((x) * (x))
#define all(x) (x).begin(), (x).end()
#define reset(x, y) memset(x, y, sizeof(x))
#define uni(x) (x).erase(unique(all(x)), (x).end())
#define BUG(x) cerr << #x << " = " << (x) << endl
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define _1 first
#define _2 second
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)

int main() {
#ifdef ONLINE_JUDGE
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#endif
  int n;
  cin >> n;
  int ans = 0;
  FOR(i, 1, n) {
    auto check = [&](int d) {
      int x = i;
      while (x) {
        if (x % d == 7) return true;
        x /= d;
      }
      return false;
    };
    if (!check(10) && !check(8)) ans++;
  }
  cout << ans;
}
