#include <bits/stdc++.h>
int main() {
  int Num;
  int numBox[9], expo, judge, ans = 0;
  scanf("%d", &Num);
  for (; Num >= 0; Num--) {
    judge = 0;
    for (expo = 0; expo < 9; expo++) numBox[expo] = Num / pow(10, expo);
    for (expo = 0; expo < 9; expo++) {
      if (!(numBox[expo] == 3 || numBox[expo] == 5 || numBox[expo] == 7)) {
        judge = 1;
        break;
      }
    }
    if (!judge) ans++;
  }
  printf("%d", ans);
  return 0;
}
