#include <bits/stdc++.h>
const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;
using namespace std;
using ll = long long int;
using edge = struct {
  int to;
  int cost;
};
ll pow_(ll a, ll n) {
  ll x = 1;
  while (n > 0) {
    if (n & 1) x = (x * a) % MOD;
    a = (a * a) % MOD;
    n >>= 1;
  }
  return x;
}
vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
map<ll, int> prime_factor(ll n) {
  map<ll, int> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}
ll factorial(int n) {
  ll ans = 1;
  for (int i = 2; i <= n; i++) {
    ans *= i;
    ans %= MOD;
  }
  return ans;
}
ll P(int n, int m) {
  ll ans = 1;
  for (int i = m + 1; i <= n; i++) {
    ans *= i;
    ans %= MOD;
  }
  return ans;
}
ll power(int n, int m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = power(n, m / 2);
    return (tmp * tmp) % MOD;
  } else {
    return (n * power(n, m - 1)) % MOD;
  }
}
ll C(int n, int m) {
  return (P(n, n - m) * power(factorial(m), MOD - 2)) % MOD;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
  ll N, ANS = 0;
  vector<ll> A;
  cin >> N;
  int po = log10(N);
  ll yo = N < 777777753 ? N : 777777753;
  if (N >= 1000) {
    ANS = pow(3, po + 1) - (pow(2, po + 1) * 3) + 3;
  }
  for (ll i = (ll)pow(10, po + 1) * 3; i <= yo; i++) {
    bool ok = true;
    bool i3 = false, i5 = false, i7 = false;
    ll p = i;
    for (ll j = 0; p != 0; j++) {
      ll o = p % 10;
      p = p / 10;
      if (o != 3 && o != 5 && o != 7) {
        ok = false;
        break;
      } else {
        if (o == 3)
          i3 = true;
        else if (o == 5)
          i5 = true;
        else if (o == 7)
          i7 = true;
      }
    }
    if (ok && i3 && i5 && i7) {
      ANS++;
    }
  }
  cout << ANS << endl;
  return 0;
}
