#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;
using vi = vector<int>;
constexpr char newl = '\n';
constexpr double eps = 1e-10;
template <typename T1, typename T2>
inline void chmin(T1& a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1& a, T2 b) {
  if (a < b) a = b;
}
template <class T>
void Print(vector<T> v) {
  for (int i = (0); i < (v.size()); i++) {
    cout << v[i] << ' ';
  }
  cout << newl;
}
template <class T>
bool lcmp(const pair<T, T>& l, const pair<T, T>& r) {
  return l.first < r.first;
}
template <class T>
istream& operator>>(istream& i, vector<T>& v) {
  for (int j = (0); j < ((int)(v).size()); j++) i >> v[j];
  return i;
}
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int N;
  cin >> N;
  int r = 0;
  for (string s = "357"; atoi(s.c_str()) <= N;) {
    bool a = false, b = false, c = false;
    for (int i = (0); i < (s.size()); i++) {
      if (s[i] == '3')
        a = true;
      else if (s[i] == '5')
        b = true;
      else
        c = true;
    }
    if (a && b && c) r++;
    int i = s.size() - 1;
    while (true) {
      if (i < 0) {
        s = '3' + s;
        break;
      }
      if (s[i] == '3') {
        s[i] = '5';
        break;
      }
      if (s[i] == '5') {
        s[i] = '7';
        break;
      }
      s[i] = '3';
      i--;
    }
  }
  cout << r;
}
