import sys

sys.setrecursionlimit(1000000000)

LET=('3','5','7')

n=int(eval(input()))



def dfs(s):

  cnt = 0

  if len(s) >0 and int(s) > n:

    return cnt

  if s.count('3') > 0 and s.count('5')>0 and s.count('7')>0:

    cnt += 1

  for l in LET:

    cnt += dfs(s+l)

  return cnt



print((dfs('')))
import sys

sys.setrecursionlimit(10000000)

n=int(eval(input()))

tex=['3','5','7']



def dfs(value):

  ans=0

  if value != '' and int(value) > n:

    return 0

  for x in tex:

    if not x in value:

      break

  else:

    ans += 1 

  for x in tex:

    ans += dfs(value+x)

  #print(value,ans)

  return ans



print((dfs('')))
import sys

sys.setrecursionlimit(1000000000)
LET = ("3", "5", "7")
n = int(eval(input()))


def dfs(s):
    cnt = 0
    if len(s) > 0 and int(s) > n:
        return cnt
    if s.count("3") > 0 and s.count("5") > 0 and s.count("7") > 0:
        cnt += 1
    for l in LET:
        cnt += dfs(s + l)
    return cnt


print((dfs("")))

import sys

sys.setrecursionlimit(10000000)
n = int(eval(input()))
tex = ["3", "5", "7"]


def dfs(value):
    ans = 0
    if value != "" and int(value) > n:
        return 0
    for x in tex:
        if not x in value:
            break
    else:
        ans += 1
    for x in tex:
        ans += dfs(value + x)
    # print(value,ans)
    return ans


print((dfs("")))

-sys.setrecursionlimit(1000000000) -LET = ("3", "5", "7") +sys.setrecursionlimit(10000000) +tex = ["3", "5", "7"] -def dfs(s): -    cnt = 0 -    if len(s) > 0 and int(s) > n: -        return cnt -    if s.count("3") > 0 and s.count("5") > 0 and s.count("7") > 0: -        cnt += 1 -    for l in LET: -        cnt += dfs(s + l) -    return cnt +def dfs(value): +    ans = 0 +    if value != "" and int(value) > n: +        return 0 +    for x in tex: +        if not x in value: +            break +    else: +        ans += 1 +    for x in tex: +        ans += dfs(value + x) +    # print(value,ans) +    return ans