#include <bits/stdc++.h>
using namespace std;
long long arr[400000] = {357, 375, 537, 573, 735, 753};
int main() {
  int last_index = 0;
  int current_index = 6;
  long long current_mul = 1000;
  while (current_mul != 10000000000LL) {
    long long bak = current_index;
    while (last_index != bak) {
      arr[current_index++] = current_mul * 3;
      arr[current_index++] = current_mul * 5;
      arr[current_index++] = current_mul * 7;
      ++last_index;
    }
    current_mul *= 10;
  }
  long long N;
  scanf("%lld", &N);
  printf("%lld\n", (long long)(upper_bound(arr, arr + current_index, N) - arr));
}
