#include <bits/stdc++.h>
using namespace std;
struct node {
  int time;
  int value;
  bool operator<(node& B) { return time < B.time; }
};
int fun(vector<node> nums, int index, int sum, int time) {
  if (index >= nums.size()) return sum;
  node p = nums[index];
  if (time < p.time)
    return sum;
  else
    return max(fun(nums, index + 1, sum, time),
               fun(nums, index + 1, sum + p.value, time - p.time));
}
int main() {
  int n;
  cin >> n;
  int yuanqi = 0;
  map<int, int> mp;
  for (int i = 100; i < n; i++) {
    bool flag = true;
    mp[3] = 0;
    mp[5] = 0;
    mp[7] = 0;
    int t = i;
    while (t) {
      int tmp = t % 10;
      if (tmp != 3 && tmp != 5 && tmp != 7) {
        flag = false;
        break;
      }
      mp[tmp] += 1;
      t = t / 10;
    }
    if (flag)
      if (mp[3] != 0 && mp[5] != 0 && mp[7] != 0) yuanqi++;
    mp.clear();
  }
  cout << yuanqi << endl;
  return 0;
}
