N = int(eval(input()))



def abc114_c(s):

  if(int(s) > N):

    return 0

  if(all(s.count(c) > 0 for c in "753")):

    ans = 1

  else:

    ans = 0

  for c in "753":

    ans += abc114_c(s+c)

  return ans

print((abc114_c("0")))
N = eval(input())

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

for i in range(len(N)):

  for num in nums:

    if(len(num) == i):

      nums.append(num + '3')

      nums.append(num + '5')

      nums.append(num + '7')

cnt = 0

for num in nums:

  if(int(num) <= int(N) and '3' in num and '5' in num and '7' in num):

    cnt += 1

print(cnt)
N = int(eval(input()))


def abc114_c(s):
    if int(s) > N:
        return 0
    if all(s.count(c) > 0 for c in "753"):
        ans = 1
    else:
        ans = 0
    for c in "753":
        ans += abc114_c(s + c)
    return ans


print((abc114_c("0")))

N = eval(input())
nums = ["3", "5", "7"]
for i in range(len(N)):
    for num in nums:
        if len(num) == i:
            nums.append(num + "3")
            nums.append(num + "5")
            nums.append(num + "7")
cnt = 0
for num in nums:
    if int(num) <= int(N) and "3" in num and "5" in num and "7" in num:
        cnt += 1
print(cnt)

-N = int(eval(input())) - - -def abc114_c(s): -    if int(s) > N: -        return 0 -    if all(s.count(c) > 0 for c in "753"): -        ans = 1 -    else: -        ans = 0 -    for c in "753": -        ans += abc114_c(s + c) -    return ans - - -print((abc114_c("0"))) +N = eval(input()) +nums = ["3", "5", "7"] +for i in range(len(N)): +    for num in nums: +        if len(num) == i: +            nums.append(num + "3") +            nums.append(num + "5") +            nums.append(num + "7") +cnt = 0 +for num in nums: +    if int(num) <= int(N) and "3" in num and "5" in num and "7" in num: +        cnt += 1 +print(cnt)