n753 = set()
for i in range(357, 77777753+1):
    s = str(i)
    if "1" in s:
        continue
    if "2" in s:
        continue
    if "4" in s:
        continue
    if "6" in s:
        continue
    if "8" in s:
        continue
    if "9" in s:
        continue
    if "3" not in s:
        continue
    if "5" not in s:
        continue
    if "7" not in s:
        continue
    n753.add(i)


N = int(input())

print(len([1 for n in n753 if n <= N]))
