#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n;
  cin >> n;
  int ans = 0;
  for (int i = 357; i <= n; i++) {
    bool ok = true;
    int m = i;
    bool c3 = false, c5 = false, c7 = false;
    while (m) {
      if (m % 10 == 3 || m % 10 == 5 || m % 10 == 7) {
        if (m % 10 == 3) {
          c3 = true;
        } else if (m % 10 == 5) {
          c5 = true;
        } else {
          c7 = true;
        }
      } else {
        ok = false;
      }
      m /= 10;
    }
    if (ok && c3 && c5 && c7) {
      ans++;
    }
  }
  cout << ans;
  return 0;
}
