#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, count = 0;
  cin >> N;
  for (int i = 1; i <= N; i++) {
    int NUM[10] = {0}, k = i, Digit;
    for (Digit = 0; k != 0; Digit++) {
      NUM[k % 10]++;
      k -= k % 10;
      k /= 10;
    }
    if (NUM[3] != 0 && NUM[5] != 0 && NUM[7] != 0 &&
        NUM[3] + NUM[5] + NUM[7] == Digit) {
      count++;
    }
  }
  cout << count;
}
