#include<bits/stdc++.h>
using namespace std;
using ll=long long;

ll n;

void f(ll cur,int use,ll &cal){
  if(cur>n) return;
  if(use==0b111) ++cal;

  f(cur*10+7,use | 0b001,cal);
  f(cur*10+5,use | 0b010,cal);
  f(cur*10+3,use | 0b100,cal);
}

int main(){
  ll ans=0;
  cin >> n;
  f(0,0,ans);
  cout << ans << endl;
  return 0;
}
