#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const double EPS = 1e-9;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int ans = 0;
  for (int i = (1); i < (n + 1); i++) {
    bool f3 = false, f5 = false, f7 = false, f = false;
    int j = i;
    while (j > 0) {
      int t = j % 10;
      if (t == 3) {
        f3 = true;
      } else if (t == 5) {
        f5 = true;
      } else if (t == 7) {
        f7 = true;
      } else {
        f = true;
        break;
      }
      j /= 10;
    }
    if (f3 && f5 && f7 && !f) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
