#include <bits/stdc++.h>
#pragma GCC optimize("O3,no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx")
using namespace std;
using Graph = vector<vector<int64_t>>;
const double pi = M_PI;
const int64_t MOD = 1000000007;
void rec(int64_t d, int64_t n, vector<int64_t> &all, bool is7, bool is5,
         bool is3) {
  if (d < n) {
    return;
  }
  if (is7 && is5 && is3) {
    all.push_back(n);
  }
  d++;
  n *= 10;
  rec(d, n + 7, all, true, is5, is3);
  rec(d, n + 5, all, is7, true, is3);
  rec(d, n + 3, all, is7, is5, true);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int64_t n;
  cin >> n;
  vector<int64_t> all;
  rec(n, 7, all, true, false, false);
  rec(n, 5, all, false, true, false);
  rec(n, 3, all, false, false, true);
  cout << all.size() << endl;
  return 0;
}
