#include <bits/stdc++.h>
using namespace std;
 
int main() {

	int  n, x, y, count, Flag;
	cin >> n;
  
  	count = 0;
	
  	for (int i = 1; i <= n; i++) {
      	Flag = 0;
      	x = i;
      	y = i;
  		for (int j = 0; j < 10; j++) {
            if ((x%10)==7 || (y%8)==7)  Flag = 1;
            x = x / 10;
            y = y / 8;
        }
      	if(Flag == 0) count++;
    }
	
  	cout << count << endl;

}


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

int main() {
string S;
cin>>S;
int ans=0;
for(int i=0;i<S.size();i++){
if(S.at(i)=='Z' && i<9){
if(S.at(i+1)=='O'){
if(S.at(i+2)=='N'){
if(S.at(i+3)=='e'){
ans++;
}else{
continue;
}
}else{
continue;
}
}else{
continue;
}
}else{
continue;
}
}
cout<<ans<<endl;
}
