#include <bits/stdc++.h>
using namespace std;
int sumdigit(int x) {
  int sum = 0;
  while (x != 0) {
    sum += x % 10;
    x /= 10;
  }
  return sum;
}
int main() {
  int N;
  cin >> N;
  int digit = to_string(N).size();
  int arr[3] = {3, 5, 7};
  int ans = 0;
  for (int d = 3; d <= digit; d++) {
    int patterns = 1;
    for (int i = 0; i < d; i++) patterns *= 3;
    for (int _trits = 0; _trits < patterns; _trits++) {
      int trits = _trits;
      bitset<3> use;
      int sum = 0;
      for (int i = 0; i < d; i++) {
        sum = sum * 10 + arr[trits % 3];
        use[trits % 3] = true;
      }
      if (use.all() && sum <= N) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
