#include <bits/stdc++.h>
using namespace std;
signed main(void) {
  long long N;
  cin >> N;
  long long ans = 0;
  for (long long n = 0; n <= 20000; n++) {
    long long nn = n;
    long long b = 0;
    while (nn > 0) {
      b *= 10;
      b += 3 + 2 * (nn % 3);
      nn /= 3;
    }
    if (b > N) continue;
    vector<bool> f(10, false);
    while (b > 0) {
      f[b % 10] = true;
      b /= 10;
    }
    if (f[3] && f[5] && f[7]) ans++;
  }
  cout << ans << endl;
  return 0;
}
