#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  return a % b == 0 ? b : gcd(b, a % b);
}
long long int dfs(long long int n, long long int N) {
  if (n > N) return 0;
  bool hasSeven = false;
  bool hasFive = false;
  bool hasThree = false;
  while (n > 0) {
    if (n % 10 == 7) {
      hasSeven = true;
    };
    if (n % 10 == 5) {
      hasFive = true;
    };
    if (n % 10 == 3) {
      hasThree = true;
    };
    n = n / 10;
  }
  long long int ret = (hasSeven && hasFive && hasThree) ? 1 : 0;
  ret += dfs(n * 10 + 7, N);
  ret += dfs(n * 10 + 5, N);
  ret += dfs(n * 10 + 3, N);
  cout << ret << endl;
  return ret;
}
int main(void) {
  long long int N;
  cin >> N;
  long long int ans = dfs(0, N);
  cout << ans;
  return 0;
}
