#include <bits/stdc++.h>
using namespace std;
int judge(long long n) {
  int a = 0, b = 0, c = 0;
  while (n != 0) {
    int y = n % 10;
    if (y == 3)
      a = 1;
    else if (y == 5)
      b = 1;
    else if (y == 7)
      c = 1;
    else
      return 0;
    n /= 10;
  }
  if (a != 0 && b != 0 && c != 0) return 1;
}
int main() {
  long long n;
  cin >> n;
  long long sum = 0;
  for (long long i = 357; i <= n; i++) {
    if (i % 10 != 3 && i % 10 != 5 && i % 10 != 7) continue;
    if (judge(i) == 1) sum++;
  }
  cout << sum << endl;
  return 0;
}
