#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
int main() {
  int n;
  cin >> n;
  int ans = 0;
  set<int> S;
  for (int i = 357; i <= n; ++i) {
    int num = i;
    S.clear();
    while (num > 0) {
      S.insert(num % 10);
      num /= 10;
    }
    if (S.size() == 3 && S.find(3) != S.end() && S.find(5) != S.end() &&
        S.find(7) != S.end()) {
      ans++;
    }
  }
  cout << ans << "\n";
  return 0;
}
