#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  int ans = 0;
  if (n >= 333) {
    for (int i = 333; i <= n; i++) {
      int num = i;
      bool ok3 = false, ok7 = false, ok5 = false;
      while (num > 0) {
        int k = num % 10;
        if (k == 3)
          ok3 = true;
        else if (k == 5)
          ok5 = true;
        else if (k == 7)
          ok7 = true;
        else
          break;
        num /= 10;
        if (num == 0 && ok3 && ok5 && ok7) {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
