#include <iostream>                                                                                                
#include <vector>                                                                                                  
#include <array>                                                                                                   
#include <set>                                                                                                     
#include <cmath>                                                                                                   
#include <string>                                                                                                  
#include <queue>                                                                                                   
#include <list>                                                                                                    
#include <unordered_map>                                                                                           
#include <algorithm>                                                                                               
#include <functional>                                                                                              
#include <iomanip> // std::std::setprecision(X)                                                                    
#include <limits>  //std::numeric_limits<int>::max(), min()                                                        
                                                                                                                   
                                                                                                                   
std::string N;                                                                                                     
std::unordered_map<std::string, bool> L;                                                                           
int solve ( int i, std::string s ) {                                                                               
  if ( i == N.size() ) {                                                                                           
    bool three = false, five = false, seven = false;                                                               
    for(int j=0; j<N.size(); j++) {                                                                                
      if ( s[j] == '3' ) three = true;                                                                             
      if ( s[j] == '5' ) five  = true;                                                                             
      if ( s[j] == '7' ) seven = true;                                                                             
    }                                                                                                              
                                                                                                                   
    if ( three && five && seven && std::stoi(s) <= std::stoi(N) && L.count(s) == 0 ) { L[s] = true; return 1; }    
    return 0;                                                                                                      
  }                                                                                                                
  return solve(i+1, "3"+s) + solve(i+1, "5"+s) + solve(i+1, "7"+s) + solve(i+1, s);                                
}                                                                                                                  
                                                                                                                   
int main (void) {                                                                                                  
                                                                                                                   
  std::cin >> N;                                                                                                   
                                                                                                                   
  std::cout << solve(0, "") << std::endl;                                                                          
                                                                                                                   
  return 0;                                                                                                        
}                                                                                                                  

Measured memory_bytes: 2944