#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1LL << 60;
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
long long lcm(long long a, long long b) {
  long long g = gcd(a, b);
  return a / g * b;
}
long long isPrime(long long n) {
  if (n < 2) {
    return 0;
  }
  for (long long i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      return 0;
    }
  }
  return 1;
}
vector<long long> getDivisor(long long n) {
  vector<long long> v;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      v.push_back(i);
      if (i != n / i) {
        v.push_back(n / i);
      }
    }
  }
  sort(v.begin(), v.end());
  return v;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  long long n;
  cin >> n;
  long long x = 1;
  long long ans = 0;
  if (n < 357) {
    cout << ans << endl;
    return 0;
  }
  if (to_string(n).size() == 4)
    ans += 6, x = 1001;
  else if (to_string(n).size() == 5)
    ans += 42, x = 10001;
  else if (to_string(n).size() == 6)
    ans += 192, x = 100001;
  else if (to_string(n).size() == 7)
    ans += 732, x = 1000001;
  else if (to_string(n).size() == 8)
    ans += 2538, x = 10000001;
  else if (to_string(n).size() == 9)
    ans += 26484, x = 100000001;
  for (long long i = x; i < n + 1; i++) {
    if (i < 357) continue;
    long long sv = 0, f = 0, t = 0;
    bool flag = true;
    string s = to_string(i);
    for (long long j = 0; j < (long long)(s.size()); j++) {
      if (s[j] == '7')
        sv++;
      else if (s[j] == '5')
        f++;
      else if (s[j] == '3')
        t++;
      else
        flag = false;
    }
    if (flag && sv > 0 && f > 0 && t > 0) ans++;
    i++;
  }
  cout << ans << endl;
  return 0;
}
