#include <bits/stdc++.h>
using namespace std;
int inputValue() {
  int a;
  cin >> a;
  return a;
};
void inputArray(int* p, int a) {
  for (int i = (0); i < (a); i++) {
    cin >> p[i];
  }
};
void inputVector(vector<int>* p, int a) {
  for (int i = (0); i < (a); i++) {
    int input;
    cin >> input;
    p->push_back(input);
  }
}
template <typename T>
void output(T a, int precision) {
  if (precision > 0) {
    cout << setprecision(precision) << a << "\n";
  } else {
    cout << a << "\n";
  }
}
void dfs(long long i, long long n, int* num) {
  if (i >= n) {
    return;
  }
  string temp = to_string(i);
  int num_3 = 0, num_5 = 0, num_7 = 0;
  for (int l0 = (0); l0 < (temp.size()); l0++) {
    if (temp[l0] == '3') {
      num_3++;
    }
    if (temp[l0] == '5') {
      num_5++;
    }
    if (temp[l0] == '7') {
      num_7++;
    }
  }
  if (num_3 > 0 & num_5 > 0 & num_7 > 0) {
    *num = *num + 1;
  }
  dfs(i * 10 + 3, n, num);
  dfs(i * 10 + 5, n, num);
  dfs(i * 10 + 7, n, num);
}
int main() {
  long long n;
  cin >> n;
  int number = 0;
  dfs(0, n, &number);
  cout << number << endl;
}
