#include<bits/stdc++.h>
#define	ll	long long
#define	pb	push_back
#define	sz(v)	(int)v.size()
#define	nl	"\n"
using namespace std;
//this fuction sorts vector pair according to first element in descending order.
bool sortinrev(const pair<int,int> &a,const pair<int,int> &b)
{
    if(a.first==b.first){
        return a.second<b.second;
    }
    return a.first<b.first;
}
int decimalToOctal(ll n) {
    int remainder; 
    int octal = 0, i = 1;
   
    while(n != 0) {
        remainder = n%8;
        if(remainder == 7) return false;
        n = n/8;
        octal = octal + (remainder*i);
        i = i*10;
    }
    return true;
}
int digit(int n)
{
	while(n != 0)
	{
		int re = n % 10;
		if(re == 7) return false;
		n/=10;
	}
	return true;
}
void solve()
{
	int n, m;
	cin>>n;
	int ans = 0;
	for(int i = 1; i<=n; i++)
	{
		if(decimalToOctal(i) && digit(i)) ans++;
	}
	cout<<ans<<nl;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(NULL);

//	int t;
//	cin>>t;
//	while(t--)
	    solve();

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  if(s.length()==3 && s[0]==s[1] && s[1]==s[2]&& s[2]==s[0]){
    cout << "Won" << endl;
  }
  else{
    cout << "Lost" << endl;
  }
  return 0;
}