#include <bits/stdc++.h>
using namespace std;
bool isValid(int);
int main() {
  int n, s = 0;
  cin >> n;
  for (int i = 100; i < n; i++) {
    if (isValid(i)) {
      s++;
    }
  }
  cout << s << endl;
  return 0;
}
bool isValid(int x) {
  int a[10] = {0};
  while (x) {
    int t = x % 10;
    a[t]++;
    x /= 10;
  }
  if (a[3] == 0 || a[5] == 0 || a[7] == 0) return false;
  for (int i = 0; i < 10; i++) {
    if (i == 3 || i == 5 || i == 7) continue;
    if (a[i] > 0) return false;
  }
  return true;
}
