import itertools as itt

N = input()

def check(snum):
    three = snum.count("3")
    five = snum.count("5")
    seven = snum.count("7")
    if (three == 0 or five == 0 or seven == 0) or (int(snum) > int(N)): return False
    else: return True

C = ["3", "5", "7"] #choice
digit = len(N)
cnt = 0
for d in range(3, digit+1): #3桁の入力から考える
    L = list(itt.product(C, repeat=d))
    for l in L:
        gen = "".join(l)
        if check(gen):
            print(gen)
            cnt += 1

print(cnt)