#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, M = N, inf = (int)1e9;
const int mod = 1e9 + 7;
int fastAbs(int n) { return (n ^ (n >> 31)) - (n >> 31); }
long long multiply(long long a, long long b) {
  return ((a % mod) * (b % mod)) % mod;
}
long long add(long long a, long long b) {
  return ((a % mod) + (b % mod)) % mod;
}
long long sub(long long a, long long b) {
  return ((a % mod) - (b % mod) + mod) % mod;
}
long long ans;
map<pair<int, int>, int> mp;
const int dx[4] = {1, 0, 0, -1};
const int dy[4] = {0, -1, 1, 0};
vector<int> h[N];
void solve() {
  int n, a = 0, b = 0, c = 0, d;
  int cnt = 0;
  cin >> n;
  int x = n;
  for (int i = 1; i <= x; i++) {
    a = b = c = 0, d = 0;
    n = i;
    while (n != 0) {
      int r = n % 10;
      n /= 10;
      if (r == 7)
        a++;
      else if (r == 5)
        b++;
      else if (r == 3)
        c++;
      else
        d++;
    }
    if (a > 0 && b > 0 && c > 0 && d == 0) cnt++;
  }
  cout << cnt;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int q = 1;
  while (q--) solve();
}
