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: def examA():
      N, M = LI()
      l = 1
      r = N
      for _ in range(M):
          L, R = LI()
          l = max(L, l)
          r = min(R, r)
      ans = max(0, r - l + 1)
      print(ans)
      return
  
  
  def examB():
      N = I()
      S = [I() for _ in range(N)]
      rest = []
      for s in S:
          if s % 10 == 0:
              continue
          rest.append(s)
      if sum(S) % 10 == 0:
          if not rest:
              print(0)
              return
          ans = sum(S) - min(rest)
      else:
          ans = sum(S)
      print(ans)
      return
  
  
  def examC():
      N, K = LI()
      K -= 1
      A = LI()
      L = A.index(1)
      # print(L)
      ans = (N - 1 + K - 1) // K
      print(ans)
      return
  
  
  def examD():
      def ketadp(a):
          n = len(a)
          dp = defaultdict(int)
          dp[0, 0, 0, 0, 0] = 1
          for i, less, has3, has5, has7 in itertools.product(
              range(n), (0, 1), (0, 1), (0, 1), (0, 1)
          ):
              max_d = 7 if less else int(a[i])
              for d in range(max_d + 1):
                  if d == 0 and has3 == 0 and has5 == 0 and has7 == 0:
                      dp[i + 1, 1, has3, has5, has7] += dp[i, less, has3, has5, has7]
                  if not (d == 3 or d == 5 or d == 7):
                      continue
                  less_ = less or d < max_d
                  has3_ = has3 or d == 3
                  has5_ = has5 or d == 5
                  has7_ = has7 or d == 7
                  dp[i + 1, less_, has3_, has5_, has7_] += dp[i, less, has3, has5, has7]
  
          ans = sum(dp[n, less, 1, 1, 1] for less in (0, 1))
          return ans
  
      N = SI()
      ans = ketadp(N)
      print(ans)
      return
  
  
  def examE():
      ans = 0
      print(ans)
      return
  
  
  def examF():
      ans = 0
      print(ans)
      return
  
  
  import sys, bisect, itertools, heapq, math, random
  from copy import deepcopy
  from heapq import heappop, heappush, heapify
  from collections import Counter, defaultdict, deque
  
  read = sys.stdin.buffer.read
  readline = sys.stdin.buffer.readline
  readlines = sys.stdin.buffer.readlines
  
  
  def I():
      return int(readline())
  
  
  def LI():
      return list(map(int, readline().split()))
  
  
  def LSI():
      return list(map(str, sys.stdin.readline().split()))
  
  
  def LS():
      return sys.stdin.readline().split()
  
  
  def SI():
      return sys.stdin.readline().strip()
  
  
  global mod, mod2, inf, alphabet, _ep
  mod = 10**9 + 7
  mod2 = 998244353
  inf = 10**18
  _ep = 10 ** (-12)
  alphabet = [chr(ord("a") + i) for i in range(26)]
  
  sys.setrecursionlimit(10**7)
  
  if __name__ == "__main__":
      examD()
  
  """
  142
  12 9 1445 0 1
  asd dfg hj o o
  aidn
  """
  
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"}]