#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int count = 0;
  for (int i = 0; i < n; i++) {
    int check[] = {0, 0, 0};
    int pow = 1;
    int digit = 0;
    int num = i;
    while (num != 0) {
      num /= 10;
      digit++;
    }
    for (int ten = 1; ten < digit + 2; ten++) {
      pow *= 10;
      if (!((i % pow) / (pow / 10) == 7 || (i % pow) / (pow / 10) == 5 ||
            (i % pow) / (pow / 10) == 3))
        break;
      switch ((i % pow) / (pow / 10)) {
        case 3:
          check[0]++;
          break;
        case 5:
          check[1]++;
          break;
        case 7:
          check[2]++;
          break;
      }
    }
    if (check[0] + check[1] + check[2] == digit &&
        (check[0] > 0 && check[1] > 0 && check[2] > 0))
      count++;
  }
  cout << count;
}
