import copy

n = int(eval(input()))

ans = 0

for i in range(2,10):

  list = ["3","5","7"]

  for j in range(i):

    dlist = []

    for k in list:

      for l in ("3","5","7"):

        dlist.append(k+l)

    list = copy.copy(dlist)

  for m in list:

    if "3" in m and "5" in m and "7" in m:

      if int(m) <= n:

        ans +=1

      else:

        print(ans)

        exit()
n = int(eval(input()))

ans = 0

def dfs(m):

  global ans

  if m > n:

    return

  sm = str(m)

  if "3" in sm and "5" in sm and "7" in sm:

    ans += 1

  dfs(m*10+3)

  dfs(m*10+5)

  dfs(m*10+7)

dfs(0)

print(ans)
import copy

n = int(eval(input()))
ans = 0
for i in range(2, 10):
    list = ["3", "5", "7"]
    for j in range(i):
        dlist = []
        for k in list:
            for l in ("3", "5", "7"):
                dlist.append(k + l)
        list = copy.copy(dlist)
    for m in list:
        if "3" in m and "5" in m and "7" in m:
            if int(m) <= n:
                ans += 1
            else:
                print(ans)
                exit()

n = int(eval(input()))
ans = 0


def dfs(m):
    global ans
    if m > n:
        return
    sm = str(m)
    if "3" in sm and "5" in sm and "7" in sm:
        ans += 1
    dfs(m * 10 + 3)
    dfs(m * 10 + 5)
    dfs(m * 10 + 7)


dfs(0)
print(ans)

-import copy - -for i in range(2, 10): -    list = ["3", "5", "7"] -    for j in range(i): -        dlist = [] -        for k in list: -            for l in ("3", "5", "7"): -                dlist.append(k + l) -        list = copy.copy(dlist) -    for m in list: -        if "3" in m and "5" in m and "7" in m: -            if int(m) <= n: -                ans += 1 -            else: -                print(ans) -                exit() + + +def dfs(m): +    global ans +    if m > n: +        return +    sm = str(m) +    if "3" in sm and "5" in sm and "7" in sm: +        ans += 1 +    dfs(m * 10 + 3) +    dfs(m * 10 + 5) +    dfs(m * 10 + 7) + + +dfs(0) +print(ans)