#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  cin >> a;
  int count = 0;
  for (int i = 0; i < a; i++) {
    int n1 = i;
    int n2 = i;
    int keta = 0;
    int count3 = 0;
    int count5 = 0;
    int count7 = 0;
    int count357 = 0;
    while (n1 > 0) {
      n1 /= 10;
      keta += 1;
    }
    if (keta < 3) {
      count = 0;
      continue;
    }
    for (int j = keta - 1; j >= 0; j--) {
      int upper = n2 / pow(10, j);
      if (upper == 3) {
        count3 += 1;
      } else if (upper == 5) {
        count5 += 1;
      } else if (upper == 7) {
        count7 += 1;
      } else {
        break;
      }
      n2 = n2 - int((n2 / pow(10, j))) * pow(10, j);
    }
    count357 = count3 + count5 + count7;
    if (count3 > 0 && count5 > 0 && count7 > 0 && count357 == keta) {
      count += 1;
    }
  }
  std::cout << count;
}
