#include <bits/stdc++.h>
using namespace std;
int finder(int x, int n) {
  int sum = 0;
  string str;
  if (x > n) return 0;
  str = to_string(x);
  if ((str.find("3") != string::npos) && (str.find("5") != string::npos) &&
      (str.find("7") != string::npos)) {
    sum = 1;
  }
  return sum + finder(x * 10 + 3, n) + finder(x * 10 + 5, n) +
         finder(x * 10 + 7, n);
}
int main() {
  unsigned int N;
  cin >> N;
  cout << finder(0, N) << endl;
  return 0;
}
