#include "bits/stdc++.h"
#define rep(i,a,n) for(int i=a;i<n;i+=2)
using namespace std;
bool judge(int num){
  int chthree=0,chfive=0,chseven=0;
  while(num>0){
    int MOD=num%10;
    if(MOD!=3&&MOD!=5&&MOD!=7)return false;
    if(MOD==3)chthree++;
    if(MOD==5)chfive++;
    if(MOD==7)chseven++;
    num/=10;
  }
  if(chthree||chfive||chseven)return false;
  return true;
}
int main(){
  int n;cin>>n;
  int ans=0;
  if(n<375)cout<<0<<endl,return 0;
  rep(i,357,n){
    if(judge(i))ans++;
  }
  cout<<ans<<endl;
}