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: # abc114_c.py
  # https://atcoder.jp/contests/abc114/tasks/abc114_c
  
  # C - 755 /
  # 実行時間制限: 2 sec / メモリ制限: 1024 MB
  # 配点 : 300点
  
  # 問題文
  
  # 整数 Nが与えられます。1 以上 N以下の整数のうち、七五三数 は何個あるでしょうか？
  # ここで、七五三数とは以下の条件を満たす正の整数です。
  #     十進法で表記したとき、数字 7, 5, 3 がそれぞれ 1回以上現れ、これら以外の数字は現れない。
  
  # 制約
  #     1≤N<109
  #     Nは整数である。
  
  # 入力
  # 入力は以下の形式で標準入力から与えられる。
  # N
  
  # 出力
  # 1以上 N以下の七五三数の個数を出力せよ。
  
  # 入力例 1
  # 575
  
  # 出力例 1
  # 4
  
  # 575
  # 以下の七五三数は、357,375,537,573 の 4個です。
  
  # 入力例 2
  # 3600
  
  # 出力例 2
  # 13
  
  # 3600以下の七五三数は、上記の 4 個と 735,753,3357,3375,3537,3557,3573,3575,3577 の計 13個です。
  
  # 入力例 3
  # 999999999
  
  # 出力例 3
  # 26484
  
  
  def calculation(lines):
      X = lines[0]
      len_x = len(X)
      # X = int(lines[0])
      # N, M = list(map(int, lines[0].split()))
  
      x = int(X)
      result = 0
  
      if len_x == 3:
          result += count_list753(3, x)
      elif len_x > 3:
          result += count_list753(3, 999)
          if len_x == 4:
              result += count_list753(4, x)
          else:
              result += count_list753(4, 9999)
              if len_x == 5:
                  result += count_list753(5, x)
              else:
                  result += count_list753(5, 99999)
                  if len_x == 6:
                      result += count_list753(6, x)
                  else:
                      result += count_list753(6, 999999)
                      if len_x == 7:
                          result += count_list753(7, x)
                      else:
                          result += count_list753(7, 9999999)
                          if len_x == 8:
                              result += count_list753(8, x)
                          else:
                              result += count_list753(8, 99999999)
                              result += count_list753(9, x)
  
      return [result]
  
  
  # その桁での結果を得る
  def count_list753(len_x, x):
      list753 = get_list753(len_x)
      cnt = 0
      for item in list753:
          if x > item:
              cnt += 1
      return cnt
  
  
  def get_list753(n):
      _, lst = get_list753_internal(n - 1, ["3", "5", "7"])
      return [int(item) for item in lst if "7" in item and "5" in item and "3" in item]
  
  
  def get_list753_internal(n, lst):
      if n == 0:
          return 0, lst
      else:
          ret = list()
          for item in lst:
              ret.append(item + "3")
              ret.append(item + "5")
              ret.append(item + "7")
          return get_list753_internal(n - 1, ret)
  
  
  # 引数を取得
  def get_input_lines(lines_count):
      lines = list()
      for _ in range(lines_count):
          lines.append(input())
      return lines
  
  
  # テストデータ
  def get_testdata(pattern):
      if pattern == 1:
          lines_input = ["575"]
          lines_export = [4]
      if pattern == 2:
          lines_input = ["3600"]
          lines_export = [13]
      if pattern == 3:
          lines_input = ["999999999"]
          lines_export = [26484]
      return lines_input, lines_export
  
  
  # 動作モード判別
  def get_mode():
      import sys
  
      args = sys.argv
      if len(args) == 1:
          mode = 0
      else:
          mode = int(args[1])
      return mode
  
  
  # 主処理
  def main():
      import time
  
      started = time.time()
      mode = get_mode()
      if mode == 0:
          lines_input = get_input_lines(1)
      else:
          lines_input, lines_export = get_testdata(mode)
  
      lines_result = calculation(lines_input)
  
      for line_result in lines_result:
          print(line_result)
  
      # if mode > 0:
      #     print(f'lines_input=[{lines_input}]')
      #     print(f'lines_export=[{lines_export}]')
      #     print(f'lines_result=[{lines_result}]')
      #     if lines_result == lines_export:
      #         print('OK')
      #     else:
      #         print('NG')
      # finished = time.time()
      # duration = finished - started
      # print(f'duration=[{duration}]')
  
  
  # 起動処理
  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"}]