#include <bits/stdc++.h>
using namespace std;
bool check753(int inp) {
  if (inp % 2 == 0) {
    return false;
  }
  vector<int> a(10, 0);
  string checki = to_string(inp);
  for (int i = 0; i < checki.length(); i++) {
    a[checki[i] - '0']++;
  }
  if (a[7] >= 1 && a[5] >= 1 && a[3] >= 1 && a[0] == 0 && a[1] == 0 &&
      a[2] == 0 && a[4] == 0 && a[6] == 0 && a[8] == 0 && a[9] == 0) {
    return true;
  } else {
    return false;
  }
}
int main() {
  int n;
  cin >> n;
  int ans = 0;
  if (n < 350) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    if (check753(i)) ans++;
  }
  cout << ans << endl;
}
