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

Int n,ans=0;
void dfs(Int x,Int a,Int b,Int c){
  if(x>n) return; 
  if(a&&b&&c) ans++;
  dfs(x*10+3,1,b,c);
  dfs(x*10+5,a,1,c);
  dfs(x*10+7,a,b,1);
}
signed main(){
  cin>>n;
  dfs(0,0,0,0);
  cout<<ans<<endl;
  return 0;
}
