#include <bits/stdc++.h>
using namespace std;
long long ans[100005];
long long fastpow(long long a, long long b) {
  if (b == 0) return 1LL;
  long long temp = fastpow(a, b / 2);
  temp = temp * temp;
  if (b % 2 == 1) temp = temp * a;
  return temp;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  long long cnt = 0;
  for (int i = 357; i <= n; i++) {
    long long t = 0, f = 0, s = 0, o = 0;
    long long temp = i;
    while (temp != 0) {
      int r = temp % 10;
      if (r == 3)
        t++;
      else if (r == 5)
        f++;
      else if (r == 7)
        s++;
      else
        o++;
      temp /= 10;
    }
    if (o > 0)
      continue;
    else if (t >= 1 && f >= 1 && s >= 1)
      cnt++;
  }
  cout << cnt;
  return 0;
}
