#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9+7;

ll n;
ll ans=0;
void dfs(ll x, bool a, bool b, bool c){
  if(x>n) return;
  if(a*b*c) ans++;

  dfs(10*x+3, true, b, c);
  dfs(10*x+5, a, true, c);
  dfs(10*x+7, a, b, true);
}
 
int main(){
  cin >> n;
  dfs(0, 0, 0, 0);
  cout << ans << endl;
  return 0;
}