#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
int main() {
  ll n;
  cin >> n;
  ll p3 = 0, p5 = 0, p7 = 0;
  ll ans = 0;
  bool q = true;
  if (n < 100000000)
    for (ll i = ll(1); i < ll(n + 1); i++) {
      ll c = i;
      while (c != 0) {
        if (c % 10 == 3)
          p3++;
        else if (c % 10 == 5)
          p5++;
        else if (c % 10 == 7)
          p7++;
        else {
          q = false;
          break;
        }
        c /= 10;
      }
      if (q && p3 > 0 && p5 > 0 && p7 > 0) ans++;
      p3 = 0, p5 = 0, p7 = 0;
      q = true;
    }
  if (n >= 800000000)
    ans = 26848;
  else if (n >= 500000000) {
    ans = 14384;
    for (ll i = ll(500000000); i < ll(n + 1); i++) {
      ll c = i;
      while (c != 0) {
        if (c % 10 == 3)
          p3++;
        else if (c % 10 == 5)
          p5++;
        else if (c % 10 == 7)
          p7++;
        else {
          q = false;
          break;
        }
        c /= 10;
      }
      if (q && p3 > 0 && p5 > 0 && p7 > 0) ans++;
      p3 = 0, p5 = 0, p7 = 0;
      q = true;
    }
  } else if (n >= 300000000) {
    ans = 8334;
    for (ll i = ll(300000000); i < ll(n + 1); i++) {
      ll c = i;
      while (c != 0) {
        if (c % 10 == 3)
          p3++;
        else if (c % 10 == 5)
          p5++;
        else if (c % 10 == 7)
          p7++;
        else {
          q = false;
          break;
        }
        c /= 10;
      }
      if (q && p3 > 0 && p5 > 0 && p7 > 0) ans++;
      p3 = 0, p5 = 0, p7 = 0;
      q = true;
    }
  } else
    ans = 8334;
  cout << ans;
}
