#include <bits/stdc++.h>
using namespace std;
long long int N;
bool shichigo(long long int a) {
  int keta = log10(a);
  keta++;
  bool is3 = false, is5 = false, is7 = false;
  for (int i = keta; i >= 0; i--) {
    int b;
    b = a / pow(10, i);
    if (b == 3)
      is3 = true;
    else if (b == 5)
      is5 = true;
    else if (b == 7)
      is7 = true;
    a -= b * pow(10, i);
  }
  if (is3 == true && is5 == true && is7 == true)
    return true;
  else
    return false;
}
int dfs(int depth, long long int a) {
  int counter = 0;
  if (depth == 9) return 0;
  if (pow(10, depth) * 3 + a < N) {
    if (shichigo(pow(10, depth) * 3 + a)) counter++;
    counter += dfs(depth + 1, pow(10, depth) * 3 + a);
  }
  if (pow(10, depth) * 5 + a < N) {
    if (shichigo(pow(10, depth) * 5 + a)) counter++;
    counter += dfs(depth + 1, pow(10, depth) * 5 + a);
  }
  if (pow(10, depth) * 7 + a < N) {
    if (shichigo(pow(10, depth) * 7 + a)) counter++;
    counter += dfs(depth + 1, pow(10, depth) * 7 + a);
  }
  return counter;
}
int main() {
  cin >> N;
  int ans = 0;
  ans = dfs(0, 0LL);
  cout << ans;
}
