#include <bits/stdc++.h>
using namespace std;
int char_count(string s, char c) {
  int cnt;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == c) cnt++;
  }
  return cnt;
}
int main() {
  unsigned long n, count = 1, th, fi, se;
  string num;
  cin >> n;
  if (n < 357) {
    cout << "0" << endl;
    return 0;
  } else if (n == 357) {
    cout << count << endl;
    return 0;
  }
  for (int i = 358; i <= n; i++) {
    num = to_string(i);
    th = char_count(num, '3');
    fi = char_count(num, '5');
    se = char_count(num, '7');
    if (th > 0 && fi > 0 && se > 0 && (th + fi + se) == num.length())
      count += 1;
  }
  cout << count << endl;
  return 0;
}
