#include <bits/stdc++.h>
using namespace std;
int CountNumber(string s, const char target_num) {
  int ret = 0;
  for (int i = 0; i < s.size(); i++)
    if (s[i] == target_num) ret++;
  return ret;
}
int main() {
  string a;
  cin >> a;
  int ret = 0;
  for (int i = 357; i < std::stoi(a); i++) {
    string s = std::to_string(i);
    int three_count = CountNumber(s, '3');
    if (three_count == 0) continue;
    int five_count = CountNumber(s, '5');
    if (five_count == 0) continue;
    int seven_count = CountNumber(s, '7');
    if (seven_count == 0) continue;
    int sum_count = three_count + five_count + seven_count;
    if (sum_count == s.size()) ret++;
  }
  cout << ret;
  return 0;
}
