#include <bits/stdc++.h>
using namespace std;
bool judge(int num) {
  int chthree = 0, chfive = 0, chseven = 0;
  while (num > 0) {
    int MOD = num % 10;
    if (MOD != 3 && MOD != 5 && MOD != 7) return false;
    if (MOD == 3) chthree++;
    if (MOD == 5) chfive++;
    if (MOD == 7) chseven++;
    num /= 10;
  }
  if (chthree || chfive || chseven) return false;
  return true;
}
int main() {
  int n;
  cin >> n;
  int ans = 0;
  if (n < 375) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 357; i < n; i += 2) {
    if (judge(i)) ans++;
  }
  cout << ans << endl;
}
