#include<iostream>
using namespace std;
int N,ans;
void rec(long num,int flag){
  if(num>N)return;
  if(flag==7)ans++;
  rec(num*10+3,flag|1);
  rec(num*10+5,flag|2);
  rec(num*10+7,flag|4);
}
int main(){
  cin>>N;
  rec(0,0);
  cout<<ans<<endl;
}
