#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
typedef vector<int> VI;
typedef vector<VI> VII;
template <class T, class U>
bool chmax(T &map<int, int> MP;, U b) {
  if (map<int, int> MP; <= b) {
    map<int, int> MP;
    = b;
    return 1;
  }
  return 0;
}
template <class T, class U>
bool chmin(T &map<int, int> MP;, U b) {
  if (map<int, int> MP; > b) {
    map<int, int> MP;
    = b;
    return 1;
  }
  return 0;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  for (int i = 0; i < (int)v.size(); i++) {
    os << v[i] << (i < v.size() - 1 ? ", " : "");
  }
  os << "}";
  return os;
}
long long n, ans = 0;
void dfs(long long x, long long map<int, int> MP;, long long b, long long c) {
  if (x > n) return;
  if (map<int, int> MP; &&b && c) ans++;
  dfs(x * 10 + 3, 1, b, c);
  dfs(x * 10 + 5, map<int, int> MP;, 1, c);
  dfs(x * 10 + 7, map<int, int> MP;, b, 1);
}
int main() {
  long long x = 0, y = 0, z = 0, k, m, h, w, ans = 0, sum = 0, Max = -1,
            Min = 1e9 + 1;
  bool ok = true;
  string t;
  cin >> n;
  dfs(0, 0, 0, 0);
  cout << ans << endl;
  return 0;
}
