#include<bits/stdc++.h>

using namespace std;

/*long long gcd(long long a,long long b){
	if(b==0){
		return a;
	}
	return(gcd(b,a%b));
}
bool prime(long long n){
	if(n<2){
		return false;
	}else{
		for(int i=2;i*i<=n;i++){
			if(n%i==0){
				return false;
			}
		}
	}
	return true;
}*/
/* PRIME FACTOR ARRAY 
vector<int> pfactor(long long n){
	vector<int>f;
	for(int i=2;i*i<=n;i++){
		while(n%i==0){
			f.push_back(i);
			n/=i;
		}
	}if(n>1){
		f.push_back(n);
	}
	return f;
}*/
 //SIEVE OF ERSATHANOS
/*bool Sieve(long long n) 
{ 
    
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
         
        if (prime[p] == true) 
        { 
              
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
   	bool a=false;
    for (int p=2; p<=n; p++){
	
       if (prime[p] && n%p==0) 
          a= true;
          break;
    }
	return a;	   
}
long long Xor(int x,int y){
	return (x | y) & (~x | ~y);
}
string dbinary(long long n){
	string a;
	for (int i = 64; i >= 0; i--) { 
        int k = n >> i; 
        if (k & 1) 
            a+='1'; 
        else
            a+='0'; 
    } 
    return a;
}*/

/*long long gcd(long long a,long long b){
	if(b==0){
		return a;
	}
	return(gcd(b,a%b));
}
bool prime(long long n){
	if(n<2){
		return false;
	}else{
		for(int i=2;i*i<=n;i++){
			if(n%i==0){
				return false;
			}
		}
	}
	return true;
}*/
/* PRIME FACTOR ARRAY 
vector<int> pfactor(long long n){
	vector<int>f;
	for(int i=2;i*i<=n;i++){
		while(n%i==0){
			f.push_back(i);
			n/=i;
		}
	}if(n>1){
		f.push_back(n);
	}
	return f;
}*/
 //SIEVE OF ERSATHANOS
/*bool Sieve(long long n) 
{ 
    
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
         
        if (prime[p] == true) 
        { 
              
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
   	bool a=false;
    for (int p=2; p<=n; p++){
	
       if (prime[p] && n%p==0) 
          a= true;
          break;
    }
	return a;	   
}
long long Xor(int x,int y){
	return (x | y) & (~x | ~y);
}
string dbinary(long long n){
	string a;
	for (int i = 64; i >= 0; i--) { 
        int k = n >> i; 
        if (k & 1) 
            a+='1'; 
        else
            a+='0'; 
    } 
    return a;
}*/
long long octo(long long deciNum)
{
 
    
    int octalNum = 0, countval = 1;
    int dNo = deciNum;
 
    while (deciNum != 0) {
 
        // decimals remainder is calculated
        int remainder = deciNum % 8;
 
        // storing the octalvalue
        octalNum += remainder * countval;
 
        // storing exponential value
        countval = countval * 10;
        deciNum /= 8;
    }
    return octalNum;
}


 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	long long n;
	cin>>n;
	long long count=0;
	long long j=1;
	while(j<=n){
		string a=to_string(j);int c=0;
		for(int i=0;i<a.length();i++){
			if(a.at(i)=='7'){
				c=1;
				count+=1;
				break;
			}
		}
		if(c==0){
			long long ans=octo(j);
			string d=to_string(ans);
			for(int i=0;i<d.length();i++){
				if(d.at(i)=='7'){
					count+=1;
					break;
				}
			}
		}
		j++;
	}
	cout<<n-count<<"\n";
	

	

	


	return 0;
}
	

#include <bits/stdc++.h>

#define int long long int
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()

using namespace std;

signed main(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  int n;
  cin >> n;
  int ans = 0;
  for(int i = 1;i <= n;i++){
    int temp = i;
    bool flag = true;
    while(temp){
      if(temp%10 == 7) flag = false;
      temp /= 10;
    }
    temp = i;
    while(temp){
      if(temp%8 == 7) flag = false;
      temp /= 8;
    }
    ans += flag;
  }
  cout << ans;
}