output_description: Print the number of the Shichi-Go-San numbers between 1 and N (inclusive).
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
attempt: import sys
  
  sys.setrecursionlimit(10**7)  # 再帰関数の上限,10**5以上の場合python
  import math
  from copy import copy, deepcopy
  from copy import deepcopy as dcp
  from operator import itemgetter
  from bisect import bisect_left, bisect, bisect_right  # 2分探索
  
  # bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
  from collections import deque
  
  # deque(l), pop(), append(x), popleft(), appendleft(x)
  ##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
  from collections import Counter  # 文字列を個数カウント辞書に、
  
  # S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
  import itertools  # 累積和
  
  # list(accumulate(l))
  from heapq import heapify, heappop, heappush
  
  # heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
  # import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
  from functools import lru_cache  # pypyでもうごく
  
  # @lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
  from decimal import Decimal
  
  
  def input():
      x = sys.stdin.readline()
      return x[:-1] if x[-1] == "\n" else x
  
  
  def printl(li):
      _ = print(*li, sep="\n") if li else None
  
  
  def argsort(s, return_sorted=False):
      inds = sorted(range(len(s)), key=lambda k: s[k])
      if return_sorted:
          return inds, [s[i] for i in inds]
      return inds
  
  
  def alp2num(c, cap=False):
      return ord(c) - 97 if not cap else ord(c) - 65
  
  
  def num2alp(i, cap=False):
      return chr(i + 97) if not cap else chr(i + 65)
  
  
  def matmat(A, B):
      K, N, M = len(B), len(A), len(B[0])
      return [
          [sum([(A[i][k] * B[k][j]) for k in range(K)]) for j in range(M)]
          for i in range(N)
      ]
  
  
  def matvec(M, v):
      N, size = len(v), len(M)
      return [sum([M[i][j] * v[j] for j in range(N)]) for i in range(size)]
  
  
  def T(M):
      n, m = len(M), len(M[0])
      return [[M[j][i] for j in range(n)] for i in range(m)]
  
  
  # ABC145-E
  def main():  # s(str)以下の非負整数で条件をK桁満たすものの個数
      N = int(input())
      A = (0, 3, 5, 7)
      ans = 0
      for x in itertools.product(A, repeat=9):
          num = 0
          for i, xi in enumerate(x):
              num += 10**i * xi
          sn = str(num)
          if num > N or "0" in sn:
              continue
          if "3" in sn and "5" in sn and "7" in sn:
              ans += 1
      print(ans)
  
  
  if __name__ == "__main__":
      main()
  
problem_description: Statement
  
  You are given an integer N. Among the integers between 1 and N (inclusive),
  how many _Shichi-Go-San numbers_ (literally "Seven-Five-Three numbers") are
  there?
  
  Here, a Shichi-Go-San number is a positive integer that satisfies the
  following condition:
  
    * When the number is written in base ten, each of the digits `7`, `5` and `3` appears at least once, and the other digits never appear.
samples: [{"input": "575", "output": "4\n    \n\nThere are four Shichi-Go-San numbers not greater than 575: 357, 375, 537 and\n573.\n\n* * *"}, {"input": "3600", "output": "13\n    \n\nThere are 13 Shichi-Go-San numbers not greater than 3600: the above four\nnumbers, 735, 753, 3357, 3375, 3537, 3557, 3573, 3575 and 3577.\n\n* * *"}, {"input": "999999999", "output": "26484"}]