#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
ll mod = 1e9 + 7;
ll rep_pow(ll a, ll b) {
  if (b == 0)
    return 1;
  else if (b % 2 == 0) {
    ll memo = rep_pow(a, b / 2);
    return memo * memo % mod;
  } else {
    return rep_pow(a, b - 1) * a % mod;
  }
}
ll nCr(ll n, ll r) {
  ll ret = 1;
  for (int i = 0; i < (int)r; i++) {
    ret *= n - i;
    ret %= mod;
    ret *= rep_pow(r - i, mod - 2);
    ret %= mod;
  }
  return ret;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
bool isPrime(int x) {
  if (x == 1)
    return false;
  else if (x == 2)
    return true;
  else if (x % 2 == 0)
    return false;
  for (int i = 3; i <= sqrt(x); i += 2) {
    if (x % i == 0) {
      return false;
    }
  }
  return true;
}
bool isNum(ll x) {
  bool nana = false, go = false, san = false;
  while (x > 0) {
    int num = x % 10;
    x /= 10;
    if (num == 3) san = true;
    if (num == 5) go = true;
    if (num == 7) nana = true;
  }
  return san && go && nana;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll n;
  cin >> n;
  queue<ll> que;
  que.push(3);
  que.push(5);
  que.push(7);
  ll ans = 0;
  ll cnt = 0;
  while (ans <= n) {
    ll x = que.front();
    que.pop();
    que.push(x * 10 + 3);
    que.push(x * 10 + 5);
    que.push(x * 10 + 7);
    if (isNum(x)) cnt++;
    ans = x;
  }
  cout << cnt << endl;
  return 0;
}
