#include <bits/stdc++.h>
int main() {
  long long N, count = 0, stock, kisyutu[3];
  char CN[8];
  scanf("%lld", &N);
  for (long long i = 1; i < N + 1; i++) {
    kisyutu[0] = 0, kisyutu[1] = 0, kisyutu[2] = 0;
    snprintf(CN, 8, "%lld", i);
    for (int j = 0; j < 8; j++) {
      if (CN[j] == '\0') {
        if ((kisyutu[0] + kisyutu[1] + kisyutu[2]) == 3) {
          count++;
        }
        break;
      }
      stock = CN[j] - '0';
      if (stock == 3)
        kisyutu[0] = 1;
      else if (stock == 5)
        kisyutu[1] = 1;
      else if (stock == 7)
        kisyutu[2] = 1;
      else
        break;
    }
  }
  printf("%d", count);
  return 0;
}
