#include <bits/stdc++.h>
using namespace std;
bool is_357(int r) {
  const string b = to_string(r);
  if (b.find('3') != string::npos) {
    if (b.find('5') != string::npos) {
      if (b.find('7') != string::npos) {
        return true;
      }
    }
  }
  return false;
}
int main(void) {
  int N;
  cin >> N;
  if (357 > N) {
    return 0;
  }
  int cnt = 0;
  for (int i = 357; i < N; i++) {
    if (is_357(i)) {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}
