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

int main() {
 int N,answer;
  answer=0;
  cin >> N;
  for(int i=1;i<N+1;i++){
    bool j=true;
    string a;
    a=std::to_string(i);
      for(int k=0;k<a.size();k++){
    if(a.at(k)!='7'&&a.at(k)!='5'&&a.at(k)!='3'){
      j=false;
    }
    if(a.at(k)=='3'||a.at(k)=='5'||a.at(k)=='7'){
      j=false;
    }  
    if((a.at(k)=='3')||(a.at(k)=='5'))||(a.at(k)=='5')||(a.at(k)=='7'))||(a.at(k)=='7')||(a.at(k)=='3')){
    j=false;  
    }
        if(j){
     answer=answer+1;
   }  
 }
  cout << answer << endl;
}