#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const int MINF = -1e9;
ll cnt = 0;
vector<int> list753;
void check(ll x) {
  string s = to_string(x);
  int size = s.size();
  bool is7_exist = false;
  bool is5_exist = false;
  bool is3_exist = false;
  for (int i = (int)0; i < (int)size; ++i) {
    if (s[i] == '3') {
      is3_exist = true;
    }
    if (s[i] == '7') {
      is7_exist = true;
    }
    if (s[i] == '5') {
      is5_exist = true;
    }
  }
  if (is7_exist && is5_exist && is3_exist) list753.push_back(x);
  return;
}
void dfs(ll x) {
  check(x);
  if (x <= 100000000) {
    dfs(10 * x + 3);
    dfs(10 * x + 5);
    dfs(10 * x + 7);
  }
}
int main() {
  ll n;
  cin >> n;
  dfs(0);
  for (int i = (int)0; i < (int)list753.size(); ++i) {
    if (list753[i] < n) {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}
