#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
using namespace std;
void _main();
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  _main();
}
const int inf = INT_MAX / 2;
const long long infl = 1LL << 60;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int N;
int v[3] = {3, 5, 7};
void _main() {
  cin >> N;
  int ans = 0;
  for (int dgt = 3; dgt < 9; dgt++) {
    int ma = 1;
    for (int i = 0; i < dgt; i++) ma *= 3;
    for (int msk = 0; msk < ma; msk++) {
      int x = 0;
      int m = msk;
      int cn[3] = {0, 0, 0};
      for (int i = 0; i < dgt; i++) {
        int d = m % 3;
        x = x * 10 + v[d];
        cn[d]++;
        m /= 3;
      }
      if (x <= N and 0 < cn[0] and 0 < cn[1] and 0 < cn[2]) ans++;
    }
  }
  cout << ans << endl;
}
