#include <bits/stdc++.h>
using namespace std;
bool is753(int n) {
  vector<bool> suc(10, 0);
  int m = n;
  while (n) {
    int digit = n % 10;
    if (digit < 3) return 0;
    if (digit == 4) return 0;
    if (digit == 6) return 0;
    if (digit > 7) return 0;
    suc[digit] = 1;
    n /= 10;
  }
  return suc[3] + suc[5] + suc[7] == 3;
}
int main() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i < n + 1; i++) ans += is753(i);
  cout << ans << endl;
}
