#include <bits/stdc++.h>
using lint = long long;
constexpr int INF = 1 << 28;
constexpr lint INFL = 1LL << 60;
constexpr int MOD = (int)1e9 + 7;
constexpr double EPS = 1e-9;
using namespace std;
namespace {
struct INIT {
  INIT() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
  }
} INIT;
}  // namespace
int main(void) {
  int n;
  cin >> n;
  const int limit = 10;
  int dp[limit + 1][2][2][2][2][2] = {0};
  dp[limit][0][0][0][1][1] = 1;
  lint base = 1;
  int border = limit;
  for (int i = 0; i < (int)(limit - 1); ++i) {
    if (border == limit && base > n) border = i;
    base *= 10;
  }
  vector<int> num{3, 5, 7};
  for (int i = (int)(limit)-1; i >= 0; --i) {
    int digit = n / base;
    n %= base;
    base /= 10;
    for (int j = 0; j < (int)(3); ++j) {
      vector<int> next(3);
      next[j] = 1;
      const int x = num[j];
      bool big = x > digit, same = x == digit;
      for (int a = 0; a < (int)(2); ++a) {
        for (int b = 0; b < (int)(2); ++b) {
          for (int c = 0; c < (int)(2); ++c) {
            for (int d = 0; d < (int)(2); ++d) {
              if (d && big) continue;
              for (int e = 0; e < (int)(2); ++e) {
                int na = a | next[0];
                int nb = b | next[1];
                int nc = c | next[2];
                int nd = d & same;
                dp[i][na][nb][nc][nd][0] += dp[i + 1][a][b][c][d][e];
              }
            }
          }
        }
      }
      if (i < border) {
        dp[i][0][0][0][0][1] = 1;
      } else {
        dp[i][0][0][0][1][1] = 1;
      }
    }
  }
  int sum = 0;
  for (int i = 0; i < (int)(2); ++i) sum += dp[0][1][1][1][i][0];
  cout << sum << endl;
  return 0;
}
