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

int main(void){
  ll n;
  cin >> n;
  
  unordered_set<ll> num;
  for (int i=1; i<=n; i++){
    string s_i = to_string(i);
    for (int j=0; j<s_i.size(); j++){
      if (s_i[j] == '7'){
        num.insert(i);
      }
    }
    stringstream ss;
    ss << oct << i;
    for (int k=0; k<ss.str().size(); k++){
      if (ss.str()[k] == '7'){
        num.insert(i);
      }
    }
  }
  cout << n - num.size() << endl;
}

#include<bits/stdc++.h>
#define fast_az_fuk ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long 
#define ull unsigned ll
#define ld long double 
#define pb push_back 
#define pf push_front
#define dll deque<ll> 
#define vll vector<ll> 
#define pll pair<ll,ll> 
#define vpll vector<pll>
#define dpll deque<pll>
#define mapll map<ll,ll>
#define endl "\n" 
#define all(v) v.begin(),v.end() 
#define ms(a,x) memset(a,x,sizeof(a))
using namespace std;
bool octal(ll a){
    while(a){
        ll r=a%8;
        if(r==7)  return 0;
        a/=8;
    }
    return 1;
}
bool decimal(ll a){
    while(a){
        ll r=a%10;
        if(r==7) return 0;
        a/=10;
    }
    return 1;
}
int32_t main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fast_az_fuk
   ll n; cin>>n;
   ll c=0;
   for(ll i=1;i<=n;i++){
    if(octal(i)&&decimal(i)) c++;
   }
   cout<<c;
    return 0;
}