#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
long long ans, n;
void Z(long long x, bool a, bool b, bool c) {
  if (x > n) return;
  if (a && b && c) ans++;
  Z(x * 10 + 3, 1, b, c);
  Z(x * 10 + 5, a, 1, c);
  Z(x * 10 + 7, a, b, c);
}
int main() {
  cin >> n;
  Z(0, 0, 0, 0);
  cout << ans << endl;
}
