#include <bits/stdc++.h>
int is753(int m) {
  static const int table[10] = {0, 0, 0, 1, 0, 2, 0, 4, 0, 0};
  int f = 0;
  while (m)
    if (table[m % 10])
      f |= table[m % 10], m /= 10;
    else
      return 0;
  return f == 7 ? 1 : 0;
}
int main() {
  int n, ans = 0;
  std::cin >> n;
  for (int i = 1; i <= n; ++i) ans += is753(i);
  std::cout << ans << std::endl;
  return 0;
}
