#include <bits/stdc++.h>
using namespace std;
bool check(long long a) {
  bool flag3 = false;
  bool flag5 = false;
  bool flag7 = false;
  string y = to_string(a);
  for (int i = 0; i < y.size(); i++) {
    if (y[i] == '3') flag3 = true;
    if (y[i] == '5') flag5 = true;
    if (y[i] == '7') flag7 = true;
  }
  if (flag3 && flag5 && flag7)
    return true;
  else
    return false;
}
int main() {
  int a;
  cin >> a;
  int count = 0;
  function<long long(long long)> dfs = [&](long long b) {
    if (b < a) {
      if (check(b)) count++;
      long long num3 = dfs(b * 10 + 3);
      long long num5 = dfs(b * 10 + 5);
      long long num7 = dfs(b * 10 + 7);
    }
    return count;
  };
  cout << dfs(0) << endl;
}
