#include <bits/stdc++.h>
//#include <atcoder/all>
#define rep(i, n) for (int i=0; i < (n); i++)
using namespace std;
//using namespace atcoder;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int NIL = -1;
const int MAX = 10000;
const int MOD = 1000000007;
const double pi = 3.141592653589;

bool is_seven_in_ten(int x){
    while(x!=0){
        if(x % 10 == 7)
            return true;
        else{
            x /= 10;
        }
    }
    return false;
}

bool is_seven_in_eight(int x){
    while(x!=0){
        if(x % 8 == 7){
            return true;
        }
        else{
            x /= 8;
        }
    }
    return false;
}

int main() {
    int n; cin >> n;
    int ten = 0, eight = 0, ten_eight = 0;
    for(int i=1;i<=n;i++){
        if(is_seven_in_eight(i) && is_seven_in_ten(i)){
            ten_eight++;
        }
        if(is_seven_in_ten(i)){
            ten++;
        }
        if(is_seven_in_eight(i)){
            eight++;
        }
    }
    
    cout << n - ten - eight + ten_eight << endl;
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define tcase int _; cin >> _; while(_--)
//#define int long long
const int MOD = 1e9+7;
const int MAX = 1e6;
const int INF = 2e9;


void solve() {
	int n;
	cin >> n;
	int a1=0, a2=0;
	vector<int> v(n, 1);
	for(int i=1; i<=n; i++) {
		int ok=1;
		int x = i;
		while(x) {
			if(x%10 == 7) ok=0;
			x /= 10;
		}
		if(!ok) v[i-1] = 0;
	}
	for(int i=1; i<=n; i++) {
		int ok=1;
		for(int j=0; j<30; j+=3) {
			if(((7<<j) & i) == (7<<j)) {
				ok=0;
				break;
			}
		}
		if(!ok) v[i-1] = 0;		
	}
	int ans=0;
	for(int x : v) ans += x;
	cout << ans << endl;
}

int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

 	solve();

  	return 0;
}

