#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
const ll INF = 1e18;
inline void chmax(ll& a, ll b) { a = max(a, b); }
inline void chmin(ll& a, ll b) { a = min(a, b); }
int main() {
  ll n;
  cin >> n;
  queue<ll> q;
  q.push(3);
  q.push(5);
  q.push(7);
  vector<ll> a(1000000000);
  vector<ll> b(1000000000);
  vector<ll> c(1000000000);
  a[3] = 1;
  b[5] = 1;
  c[7] = 1;
  ll cnt = 0;
  while (!q.empty()) {
    ll now = q.front();
    q.pop();
    if (now > n) {
      break;
    }
    ll x = now * 10 + 3;
    a[x]++;
    q.push(x);
    ll y = now * 10 + 5;
    b[y]++;
    q.push(y);
    ll z = now * 10 + 7;
    c[z]++;
    q.push(z);
    if (a[x] > 0 && b[x] > 0 && c[x] > 0) cnt++;
    if (a[y] > 0 && b[y] > 0 && c[y] > 0) cnt++;
    if (a[z] > 0 && b[z] > 0 && c[z] > 0) cnt++;
  }
  cout << cnt << endl;
  return 0;
}
