#include <bits/stdc++.h>
using namespace std;
bool isX(long long a) {
  int flag3 = 0;
  int flag5 = 0;
  int flag7 = 0;
  while (a != 0) {
    if (a % 10 == 3)
      flag3 = 1;
    else if (a % 10 == 5)
      flag5 = 1;
    else if (a % 10 == 7)
      flag7 = 1;
    else
      return false;
    a /= 10;
  }
  if (flag3 == 1 && flag5 == 1 && flag7 == 1)
    return true;
  else
    return false;
}
int main() {
  long long N, Xval = 0;
  scanf("%lld", &N);
  for (long long i = 0; i <= N; i++) {
    if (isX(i)) Xval++;
  }
  printf("%d\n", Xval);
}
