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

ll n, ans;
void dfs(ll a, ll b, ll c, ll x){
  if(x > n) return;
  if(a && b && c) ans++;

  dfs(1, b, c, 10 * x + 3);
  dfs(a, 1, c, 10 * x + 5);
  dfs(a, b, 1, 10 * x + 7);
}

int main(){
  cin >> n;

  dfs(0, 0, 0, 0);
  
  cout << ans << endl;

  return 0;

}