#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int v = 0;
  for (int i = 1; i <= n; i++) {
    bool f7 = 0, f5 = 0, f3 = 0;
    for (int t = i; t > 0; t /= 10) {
      if (t % 10 == 7)
        f7 = 1;
      else if (t % 10 == 5)
        f5 = 1;
      else if (t % 10 == 3)
        f3 = 1;
      else
        break;
      if (t / 10 == 0 && f7 == 1 && f5 == 1 && f3 == 1) v++;
    }
  }
  cout << v << endl;
  return 0;
}
