#include <bits/stdc++.h>
using namespace std;
template <class T>
void umin(T &a, T b) {
  a = min(a, b);
}
template <class T>
void umax(T &a, T b) {
  a = max(a, b);
}
const int dx[] = {1, 0, -1, 0, -1, -1, 1, 1},
          dy[] = {0, 1, 0, -1, -1, 1, -1, 1};
const int mod = 1e9 + 7;
const long long N = 1e5 + 4;
long long n, m, ans;
vector<long long> v;
void calc(long long x) {
  if (x > 1e10) return;
  v.push_back(x);
  calc(x * 10LL + 5LL);
  calc(x * 10LL + 3LL);
  calc(x * 10LL + 7LL);
}
bool isgood(long long i) {
  bool a3 = 0, a5 = 0, a7 = 0;
  while (i > 0) {
    if (i % 10 == 3) a3 = 1;
    if (i % 10 == 5) a5 = 1;
    if (i % 10 == 7) a7 = 1;
    i /= 10;
  }
  if (a3 == 1 && a5 == 1 && a7 == 1) return 1;
  return 0;
}
void solve() {
  cin >> n;
  calc(3LL);
  calc(5LL);
  calc(7LL);
  vector<long long> g;
  for (auto i : v) {
    if (isgood(i)) g.push_back(i);
  }
  for (auto i : g) {
    if (i < n) ans++;
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T = 1;
  while (T--) solve();
  return 0;
}
