#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;
ll mod = 1e9 + 7;
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll f(ll a) {
  ll a3 = 0, a5 = 0, a7 = 0;
  bool w = true;
  while (a > 0) {
    if (a % 10 == 3)
      a3 = 1;
    else if (a % 10 == 5)
      a5 = 1;
    else if (a % 10 == 7)
      a7 = 1;
    else {
      w = false;
      break;
    }
    a /= 10;
  }
  if (a3 * a5 * a7 == 1 && w)
    return 1;
  else
    return 0;
}
ll a[110000];
int main() {
  ll x, t, n, m, k, tmp = 0, ans = 0;
  cin >> n;
  if (n < 10) {
    ans = 0;
  } else if (n < 100) {
    ans = 0;
  } else if (n < 1000) {
    for (ll i = ll(100); i < ll(n + 1); i++) ans += f(i);
  } else if (n < 10000) {
    ans = 6;
    for (ll i = ll(1000); i < ll(n + 1); i++) {
      ans += f(i);
    }
  } else if (n < 1e5) {
    ans = 42;
    for (ll i = ll(10000); i < ll(n + 1); i++) ans += f(i);
  } else if (n < 1e6) {
    ans = 192;
    for (ll i = ll(100000); i < ll(n + 1); i++) ans += f(i);
  } else if (n < 1e7) {
    ans = 732;
    for (ll i = ll(1000000); i < ll(n + 1); i++) ans += f(i);
  } else if (n < 1e8) {
    ans = 2538;
    for (ll i = ll(10000000); i < ll(n + 1); i++) ans += f(i);
  } else if (n <= 300000000) {
    ans = 2538;
  } else if (n <= 500000000) {
    ans = 2538;
    for (ll i = ll(300000000); i < ll(40000000); i++) ans += f(i);
  } else if (n <= 700000000) {
    ans = 14384;
    for (ll i = ll(500000000); i < ll(600000000); i++) ans += f(i);
  } else if (n <= 800000000) {
    ans = 20434;
    for (ll i = ll(700000000); i < ll(n + 1); i++) ans += f(i);
  } else
    ans = 26484;
  cout << ans;
}
