#include <iostream>
#include <algorithm>
#include <string>
#include <complex>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

#include <chrono>
#include <random>
#include <cassert>

//#include <atcoder/all>

using namespace std;
//using namespace atcoder;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define REP(i,n,m) for(int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(a) { cerr << #a << " = " << a << endl;}
#define debugV(vec) { cerr << #vec << " : "; for(auto v : vec) cerr << v << " "; cerr << endl; }
#define debug2D(vec2D, w) { cerr << #vec2D << endl;  for(auto vec : vec2D) { for (auto v : vec) cerr << setw(w) << v << " "; cerr << endl; } } 
#define debugVP(vec) { cerr << #vec << " : ";  for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;}
#define debug2DP(vec2D) { cerr << #vec2D << endl;  for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } }

typedef long long ll;

constexpr ll INF = 1e14; //32 ~2*10^10 //64 ~9*10^19
//constexpr ll MOD = 998244353;
constexpr ll MOD = 1000000007;
const double EPS = round(1e-6);
const char en = '\n';


struct Edge {
	Edge(int _s, int _t, ll _cost = 1) : from(_s), to(_t), cost(_cost) {};
	int from, to;
	ll cost;
	//ll fee;
};

typedef vector<vector<Edge>> Graph;

void add_edge(Graph& g, int from, int to, ll cost = 1) {
	g[from].push_back(Edge(from, to, cost));
}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } else return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } else return false; }

//int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};


void solve() {
	ll n; cin >>n;

	ll ans = 0;
	auto f = [&](int a, int m) {
	  bool ok = true;
		while (a > 0) {
			if (a % m == 7) { ok = false; break;}
			a /= m;
		}
		return ok;
	};

	rep1(i, n) {
		if (f(i,10) && f(i,8)) ++ans;
	}
	cout << ans <<en;
	
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	//rep(i,3)
	solve();

}
#include<bits/stdc++.h>
using namespace std;
#define ll long long
bool decimal(ll n)
{
    while(n)
    {
        int r=n%10;
        if(r==7)
        return true;
        n/=10;
    }
    return false;
}
bool octal(ll n)
{
    while(n)
    {
        int r=n%8;
        if(r==7)
        return true;
        n/=8;
    }
    return false;
}
int main()
{
        ll n; 
        cin>>n;
        int a[n+1];
        memset(a,0,sizeof(a));
    
        for(int i=1;i<=n;i++){
          if(a[i]==0){
              if(decimal(i))
                  a[i]=1;
              else if(octal(i))
                  a[i]=1;
          }
        }
  		int ans = 0;
        for(int i=1;i<=n;i++)
        	if(a[i]==0)
        		ans++;
        cout<<ans<<endl;
        return 0;
}