#include<bits/stdc++.h>
using namespace std;
int dfs(long long sum,long long t,int bits);
int d[]={3,5,7};
int n;

int main(){
  cin>>n;
  cout<<dfs(0,1,0)<<endl;
  return(0);
}

int dfs(long long sum,long long t,int bits){
  int rec=0;
  if(bits==7)rec++;
  if(sum>n)return 0;
  for(int i=0;i<3;i++){
    rec+=dfs(sum+d[i]*t,t*10,bits|(1<<i));
  }
  return rec;
}
