#include <bits/stdc++.h>
using namespace std;
bool isT(int tm) {
  bool flag = 1;
  int cnt = 0;
  bool f_3 = 1;
  bool f_5 = 1;
  bool f_7 = 1;
  while (tm > 0 && flag) {
    int t = tm % 10;
    if (t == 0) flag = 0;
    if (!(t == 3 || t == 5 || t == 7)) flag = 0;
    if (cnt < 3) {
      if (t == 3 && f_3) {
        f_3 = 0;
        cnt++;
      }
      if (t == 5 && f_5) {
        f_5 = 0;
        cnt++;
      }
      if (t == 7 && f_7) {
        f_7 = 0;
        cnt++;
      }
    }
    tm /= 10;
  }
  if (cnt < 3) flag = 0;
  return flag;
}
int fun1(int t) {
  int ans = 0;
  for (int i = 357; i <= t;) {
    if (isT(i)) {
      ans++;
    }
    i = i + 2;
  }
  return ans;
}
int main() {
  int t;
  cin >> t;
  int ans;
  ans = fun1(t);
  cout << ans;
  return 0;
}
