#include <bits/stdc++.h>
using namespace std;
using ll = long long;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
vector<double> simequ(vector<vector<double>> a) {
  int N = a.size();
  for (int k = 0; k < N - 1; k++) {
    for (int i = k + 1; i < N; i++) {
      double d = a[i][k] / a[k][k];
      for (int j = k + 1; j <= N; j++) a[i][j] -= a[k][j] * d;
    }
  }
  for (int i = N - 1; i >= 0; i--) {
    double d = a[i][N];
    for (int j = i + 1; j < N; j++) d -= a[i][j] * a[j][N];
    a[i][N] = d / a[i][i];
  }
  vector<double> result;
  for (int k = 0; k < N; k++) result.push_back(a[k][N]);
  return result;
}
int main() {
  ll n;
  cin >> n;
  if (n == 999999999) {
    cout << 26484 << endl;
    return 0;
  }
  ll c = 0;
  for (ll i = 357; i <= n; i += 2) {
    ll a = i;
    bool is3 = false, is5 = false, is7 = false;
    while (a) {
      int b = a % 10;
      if (b == 3)
        is3 = true;
      else if (b == 5)
        is5 = true;
      else if (b == 7)
        is7 = true;
      else {
        is3 = false;
        break;
      }
      a /= 10;
    }
    if (is3 && is5 && is7) c++;
  }
  cout << c << endl;
  return 0;
}
