#include <iostream>
#include <algorithm>
using namespace std;
 
long long n;
int ans=0;
void dfs(long x,bool a,bool b,bool c){
  if(x>n)return;
  
  if(a&&b&&c)ans++;
  dfs(x*10+7,true,b,c);
  dfs(x*10+5,a,true,c);
  dfs(x*10+3,a,b,true);
  
}
int main(){
  cin>>n;
  dfs(0,false,false,false);
  cout<<ans<<endl;
  return 0;
}