#include <bits/stdc++.h>
using namespace std;
bool check(int x) {
  bool ok = false;
  int a = 0;
  int b = 0;
  int c = 0;
  for (char l : to_string(x)) {
    if (l == '3')
      a++;
    else if (l == '5')
      b++;
    else
      c++;
  }
  if (a && b && c) ok = true;
  return ok;
}
int calc(int x, int n) {
  int num[3] = {7, 5, 3};
  if (x > n) return 0;
  int s = 0;
  if (check(x))
    s = 1;
  else
    s = 0;
  for (int i : num) s += calc(10 * x + i, n);
  return s;
}
int main() {
  int n;
  cin >> n;
  cout << calc(0, n) << endl;
}
