#include <bits/stdc++.h>
using namespace std;
vector<long long> num753;
void append(long long n) {
  if (n < 1e9) {
    num753.push_back(n);
    append(n * 10 + 3);
    append(n * 10 + 5);
    append(n * 10 + 7);
  }
}
int main() {
  int N;
  cin >> N;
  append(0);
  int n = num753.size();
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (num753[i] < N) {
      string S = to_string(num753[i]);
      if (find(S.begin(), S.end(), '3') != S.end() &&
          find(S.begin(), S.end(), '5') != S.end() &&
          find(S.begin(), S.end(), '7') != S.end()) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}
