#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<map>
#include<list>
using namespace std;
#define ll long long

int main(){
  ll N;
  cin >> N;
  list<ll> v;
  v.push_back(3);
  v.push_back(5);
  v.push_back(7);
  ll cnt;
  for(auto itr = v.begin();itr !=v.end(); ++itr){
     if(*itr*10+3<=N)v.push_back(*itr*10+3);
     if(*itr*10+5<=N)v.push_back(*itr*10+5);
     if(*itr*10+7<=N)v.push_back(*itr*10+7);
     cnt+=judge753(*itr);
    }
    cout <<cnt <<endl;
    return 0;
}

ll judge753(ll a){
  bool flag3=0;
  bool flag5=0;
  bool flag7=0;
  int tmp;
  while(a>0){
    tmp=a%10;
    if(tmp==3)flag3=1;
    if(tmp==5)flag5=1;
    if(tmp==7)flag7=1;
    a=a/10;
  }
  if(flag3*flag5*flag7){
    return 1;
  }else{
    return 0;
  }
}
