#include <bits/stdc++.h>
int main(void) {
  int n;
  std::cin >> n;
  int n753 = 0;
  for (int i = 1; i <= n; ++i) {
    std::string str_i = std::to_string(i);
    std::vector<int> nums(str_i.size());
    for (int j = 0; j < str_i.size(); ++j) nums[j] = (str_i[j] - '0');
    int n3 = 0, n5 = 0, n7 = 0;
    for (int j = 0; j < nums.size(); ++j) {
      if (nums[j] == 3)
        ++n3;
      else if (nums[j] == 5)
        ++n5;
      else if (nums[j] == 7)
        ++n7;
    }
    if (n3 >= 1 && n5 >= 1 && n7 >= 1 && n3 + n5 + n7 == nums.size()) ++n753;
  }
  std::cout << n753 << std::endl;
  return 0;
}
