#include <vector>
#include <iostream>
#include <cmath>
#include <string>

using namespace std;

typedef long long ll;

ll N;
ll ans=0;

void dfs(ll a, int flags){
  if(a>N) return;
  if(flags==7) ans++;
  dfs(a*10+3, flags|1);dfs(a*10+5, flags|2);dfs(a*10+7, flags|4);
}

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