#include<iostream>
#define FAST ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)

using namespace std;
typedef long long ll;

const int MAXN=1e5+5;

int ok(int n, int base) {
    while(n) {
        if(n%base == 7) return 0;
        n/=base;
    }
    return 1;
}
int main() {
    FAST;
    int n; cin>>n;
    int ans=0;
    for(int i=1;i<=n;++i) {
        if(ok(i, 8) && ok(i, 10)) ++ans;
    }
    cout<<ans<<endl;
}
#include <bits/stdc++.h>
using namespace std;

int main(){
  int N;
  cin >> N;
  
  cout << N - 1;
}