#include <bits/stdc++.h>
using namespace std;
bool judge(long long x) {
  int f3 = 0, f5 = 0, f7 = 0;
  int a;
  while (x != 0) {
    a = x % 10;
    x = x / 10;
    if (a == 3)
      f3 = 1;
    else if (a == 5)
      f5 = 1;
    else if (a == 7)
      f7 = 1;
    else
      return false;
    if (f3 == 1 && f5 == 1 && f7 == 1) return true;
  }
  return false;
}
int main() {
  map<long long, int> mp;
  long long t;
  int num;
  while (scanf("%lld", &t) == 1) {
    num = 0;
    if (t >= 357) {
      for (long long i = 357; i <= t; i++) {
        if (i % 2 == 1 && mp[i] != 2) {
          if (judge(i) == true)
            num++;
          else {
            int p = 0;
            while (i != 0) {
              i /= 10;
              p++;
            }
            for (long long j = i; j <= t; j += 1 * pow(10, p)) mp[j] = 2;
          }
        }
      }
    }
    printf("%d\n", num);
  }
  return 0;
}
