#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    bool counter3 = 0;
    bool counter5 = 0;
    bool counter7 = 0;
    int n = i;
    while (true) {
      int k = n % 10;
      if (k == 3) {
        if (counter3 == false) {
          counter3 = true;
        }
      } else if (k == 5) {
        if (counter5 == false) {
          counter5 = true;
        }
      } else if (k == 7) {
        if (counter7 == false) {
          counter7 = true;
        }
      } else {
        break;
      }
      n = n / 10;
      if (n == 0 && counter3 && counter5 && counter7) {
        ans++;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
