#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, count = 0;
  string str;
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    str = to_string(i);
    if (str.find("0") != string::npos || str.find("1") != string::npos ||
        str.find("2") != string::npos || str.find("4") != string::npos ||
        str.find("6") != string::npos || str.find("8") != string::npos ||
        str.find("9") != string::npos)
      continue;
    if (str.find("3") != string::npos && str.find("7") != string::npos &&
        str.find("5") != string::npos) {
      count++;
    } else
      continue;
  }
  printf("%d\n", count);
}
