#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  if (n < 357) {
    printf("0");
    return 0;
  }
  int a[8];
  a[3] = 0;
  a[5] = 0;
  a[7] = 0;
  int cou = 0;
  while (n >= 357) {
    int k = n;
    while (k > 0) {
      int c = k % 10;
      if (c == 3 || c == 5 || c == 7)
        a[c]++;
      else {
        a[3] = 0;
        a[5] = 0;
        a[7] = 0;
        break;
      }
      k = k / 10;
    }
    if (a[3] > 0 && a[5] > 0 && a[7] > 0) {
      cou++;
    }
    n--;
  }
  printf("%d", cou);
}
