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