#include <bits/stdc++.h>
using namespace std;
using ll = long long;
bool is_valid(ll num) {
  vector<bool> cnt_753(3, false);
  while (num > 0) {
    int now = num % 10;
    num /= 10;
    switch (now) {
      case 3:
        cnt_753[0] = true;
      case 5:
        cnt_753[1] = true;
      case 7:
        cnt_753[2] = true;
    }
  }
  return cnt_753[0] and cnt_753[1] and cnt_753[2];
}
int main() {
  int N;
  cin >> N;
  vector<ll> cands = {0};
  int cnt = 0;
  for (;;) {
    vector<ll> new_cands;
    for (auto &cand : cands) {
      for (auto n : {3, 5, 7}) {
        long long now = cand * 10 + n;
        if (now <= N) new_cands.push_back(now);
      }
    }
    swap(cands, new_cands);
    for (auto cand : cands)
      if (is_valid(cand)) ++cnt;
    if (cands.size() == 0) break;
  }
  cout << cnt << endl;
  return 0;
}
