#include <bits/stdc++.h>
using namespace std;
long long unsigned int N;
vector<long long unsigned int> X;
int main() {
  cin >> N;
  long long unsigned int ans = 0;
  uint is7, is5, is3, no753;
  for (long long unsigned int i = 0; i < N; i++) {
    long long unsigned int n = i + 1;
    is7 = 0;
    is5 = 0;
    is3 = 0;
    no753 = 0;
    while (n > 0) {
      uint j = n % 10;
      if (j != 7 && j != 5 && j != 3) {
        no753 = 1;
        break;
      }
      if (j == 7) {
        is7 += 1;
      }
      if (j == 5) {
        is5 += 1;
      }
      if (j == 3) {
        is3 += 1;
      }
      n = n / 10;
    }
    if (is7 > 0 && is5 > 0 && is3 > 0 && no753 == 0) {
      ans += 1;
    }
  }
  cout << ans << endl;
}
