#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
ll res = 0;
ll n, cnt;
void dfs(ll now, ll use) {
  if (now > n) {
    return;
  }
  if (use == 7) {
    cnt++;
  }
  dfs(now * 10 + 3, use | 0b100);
  dfs(now * 10 + 5, use | 0b010);
  dfs(now * 10 + 7, use | 0b001);
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  cin >> n;
  ll cnt = 0;
  dfs(0, 0);
  cout << cnt << endl;
}
