#include<bits/stdc++.h>
using namespace std;
int main(){
  long N;
  cin >> N;
  long ans = 0;
  long i;
  int chk[3]={0,0,0};
  int wa;
  if(N<357) ans = 0;
  long tmp;
  
  else{
    for(i=357;i<=N;i+=2){
      chk[0]=0;
      chk[1]=0;
      chk[2]=0;
      wa = 1;
      tmp = i;
      while(tmp>0){
        switch(tmp%10){
          case 3:
            chk[0]++;
            break;
          case 5;
            chk[1]++;
            break;
          case 7;
            chk[2]++;
            break;
          default
            wa = 0;
            break;
          }
          tmp /= 10;
        }
      if(chk[0]>0 && chk[1]>0 && chk[2]>0 && wa ==1) ans++;
      }
    }

    cout << ans;
}
