#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long MOD = 1e9 + 7;
const long long LINF = 1e18;
struct mint {
  long long x;
  mint() : x(0) {}
  mint(long long x) : x((x % MOD + MOD) % MOD) {}
  mint& operator+=(const mint& r) {
    if ((x += r.x) >= MOD) {
      x -= MOD;
    }
    return *this;
  }
  mint& operator-=(const mint& r) {
    if ((x -= r.x) < 0) {
      x += MOD;
    }
    return *this;
  }
  mint& operator*=(const mint& r) {
    if ((x *= r.x) > MOD) {
      x %= MOD;
    }
    return *this;
  }
  mint& operator++() {
    if ((++x) >= MOD) {
      x -= MOD;
    }
    return *this;
  }
  mint operator++(int) {
    mint ret = x;
    if ((++x) >= MOD) {
      x -= MOD;
    }
    return ret;
  }
  mint& operator--() {
    if ((--x) < 0) {
      x += MOD;
    }
    return *this;
  }
  mint operator--(int) {
    mint ret = x;
    if ((--x) < 0) {
      x += MOD;
    }
    return ret;
  }
  mint operator+(const mint& r) {
    mint ret;
    return ret = x + r.x;
  }
  mint operator-(const mint& r) {
    mint ret;
    return ret = x - r.x;
  }
  mint operator*(const mint& r) {
    mint ret;
    return ret = x * r.x;
  }
  mint operator-() { return mint() - *this; }
  bool operator<(const mint& a) { return x < a.x; }
  bool operator>(const mint& a) { return x > a.x; }
  bool operator<=(const mint& a) { return x <= a.x; }
  bool operator>=(const mint& a) { return x >= a.x; }
  bool operator==(const mint& a) { return x == a.x; }
  bool operator!=(const mint& a) { return x != a.x; }
};
ostream& operator<<(ostream& os, const mint& r) {
  os << r.x;
  return os;
}
ostream& operator>>(ostream& os, const mint& r) {
  os >> r.x;
  return os;
}
void solve(istream& cin, ostream& cout) {
  int n;
  cin >> n;
  vector<long long> a = {3, 5, 7};
  vector<long long> b;
  queue<long long> q;
  for (int i = (0); i <= (a.size() - 1); i++) q.push(a[i]);
  while (q.front() < n) {
    long long x = q.front();
    q.pop();
    string s = to_string(x);
    if (s.find("3") != -1 && s.find("5") != -1 && s.find("7") != -1)
      b.push_back(x);
    for (int i = (0); i <= (a.size() - 1); i++) q.push(x * 10 + a[i]);
  }
  int ans;
  ans = b.size();
  cout << ans << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;
  solve(cin, cout);
}
